jaguar_jwt 2.1.5 jaguar_jwt: ^2.1.5 copied to clipboard
Provides JWT utilities for Dart including issuing a token, verifing a token and parsing a token.
jaguar_jwt #
JWT utilities for Dart and Jaguar.dart
Usage #
Issuing JWT token #
final key = 'dfsdffasdfdgdfgdfg456456456';
final claimSet = new JwtClaim(
subject: 'kleak',
issuer: 'teja',
audience: <String>['example.com', 'hello.com'],
payload: {'k': 'v'});
String token = issueJwtHS256(claimSet, key);
print(token);
Decoding JWT token #
final JwtClaim decClaimSet = verifyJwtHS256Signature(token, key);
print(decClaimSet.toJson());
Validating JWT token #
decClaimSet.validate(issuer: 'teja', audience: 'hello.com');
Configuration #
JwtClaimSet #
JwtClaimSet
is the model to holds JWT claim set information.
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 token.Subject
Subject of the JWT token. Usually stores the user ID of the user to which the token is issued. Fills thesub
field of the JWT token.audience
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 token.expiry
Time at which the token expires. Fillsexp
field in JWT token.jwtId
Unique identifier across services that identifies the token. Fillsjti
field in JWT token.