JWT utilities for Dart and Jaguar.dart
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);
final JwtClaim decClaimSet = verifyJwtHS256Signature(token, key);
print(decClaimSet.toJson());
decClaimSet.validate(issuer: 'teja', audience: 'hello.com');
JwtClaimSet
is the model to holds JWT claim set information.
To issue a JWT token, it needs:
issuer
iss
field of the JWT token.Subject
sub
field of the JWT token.audience
aud
field in JWT token.expiry
exp
field in JWT token.jwtId
jti
field in JWT token.iat
(issued at) fieldissueJwtHS256
function to issue a JWT HS256 based tokenverifyJwtHS256Signature
to verify the signature and structure of JWT tokenexample/example.dart
library jaguar_jwt.example;
import 'package:jaguar_jwt/jaguar_jwt.dart';
void main() {
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);
final JwtClaim decClaimSet = verifyJwtHS256Signature(token, key);
print(decClaimSet.toJson());
decClaimSet.validate(issuer: 'teja', audience: 'hello.com');
}
Add this to your package's pubspec.yaml file:
dependencies:
jaguar_jwt: "^1.1.5"
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter packages get
Alternatively, your editor might support pub get
or packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:jaguar_jwt/jaguar_jwt.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
1.1.5 | Feb 2, 2018 |
|
|
0.3.9 | Feb 2, 2018 |
|
|
0.3.8 | Feb 2, 2018 |
|
|
0.3.7 | Feb 2, 2018 |
|
|
0.3.6 | Feb 2, 2018 |
|
|
0.3.5 | Nov 4, 2017 |
|
|
0.3.4 | Nov 4, 2017 |
|
|
0.3.3 | Jul 15, 2017 |
|
|
0.3.2 | Jul 15, 2017 |
|
|
0.3.1 | Jul 15, 2017 |
|
|
We analyzed this package on Apr 9, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
71 | / 100 |
Health:
Code health derived from static analysis.
[more]
|
93 | / 100 |
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
100 | / 100 |
Overall score:
Weighted score of the above.
[more]
|
83 |
Detected platforms: Flutter, web, other
No platform restriction found in primary library
package:jaguar_jwt/jaguar_jwt.dart
.
Fix analysis and formatting issues.
Analysis or formatting checks reported 11 hints.
Strong-mode analysis of
lib/src/jaguar_jwt.dart
gave the following hint:line: 170 col: 31
'BASE64URL' is deprecated and shouldn't be used.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=1.20.0 <3.0.0 | ||
auth_header | >=0.0.2 <0.1.0 | 0.0.3 | |
crypto | >=2.0.1 <3.0.0 | 2.0.2+1 | |
Transitive dependencies | |||
charcode | 1.1.1 | ||
collection | 1.14.9 | ||
convert | 2.0.1 | ||
typed_data | 1.1.5 | ||
Dev dependencies | |||
test | >=0.12.0 <0.13.0 |