jaguar_jwt 0.2.0 jaguar_jwt: ^0.2.0 copied to clipboard
JWT utilities for Jaguar.dart
jaguar_jwt #
JWT utilities for Jaguar.dart
Configuration #
AuthenticationConf #
AuthenticationConf
object holds configuration to issue JWT token during authentication phase.
To issue a JWT token, it needs:
issuer
Authority issuing the token. This will be used during authorization to verify that expected issuer has issued the token. Fills theiss
field of the JWT tokenaudience
List of audience that accept this token. This will be used during authorization to verify that JWT token has expected audience for the service. Fillsaud
field in JWT tokentokenDuration
Duration for which the issued JWT token is valid. Fillsexp
field in JWT tokensignatureContext
The signature context to sign the JWT token with
AuthorizationConf #
AuthorizationConf
object holds configuration to decode and validate JWT token during authorization phase.
issuer
The allowed/expected issuer. The issuer of the incoming JWT token must match this field for authorization to succeedaudience
Allowed audience. Incoming JWT token must contain at least one of these audiences for the authorization to succeed.signatureContext
The signature context to verify the signature of JWT token.
Usage #
Encoding/issuing JWT token #
final encoder = new AuthenticationConf.SymmetricKey(
'dfsdffasdfdgdfgdfg456456456', 'teja',
audience: <String>['admin', 'students']);
ClaimSet claimSet =
new ClaimSet('kleak', encoder.issuer, encoder.audience, {'k': 'v'});
String encoded = encoder.encodeClaimSet(claimSet);
print(encoded);
Decoding JWT token #
final decoder = new AuthorizationConf.SymmetricKey(
'dfsdffasdfdgdfgdfg456456456', 'teja',
audience: <String>['students']);
JsonWebToken decoded = decoder.decodeToken(encoded);
print(decoded.claimSet.toJson());