O'Reilly logo

Mastering Internet of Things by Peter Waher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Validating tokens

The Waher.Security.JWT.UWP library also contains the JwtAuthentication class that authenticates web requests based on JWT tokens. We first need to define a variable for it:

private JwtAuthentication tokenAuthentication; 

When we've established the device identity, which we will use as a realm, we create an instance of this authenticator (the realm allows browsers to isolate credentials between sites):

this.tokenAuthentication = new JwtAuthentication(this.deviceId, 
   this.users, this.tokenFactory); 

The authenticator references our users database to check that subjects match users in the database. It also references the token factory to validate that tokens are correctly signed. We then simply add the reference to the authenticator ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required