dart_jsonwebtoken 2.1.0
dart_jsonwebtoken: ^2.1.0 copied to clipboard

A dart implementation of the famous javascript library 'jsonwebtoken' (JWT).

JSON Web Token (JWT) #

pub package

A dart implementation of the famous javascript library jsonwebtoken.

JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.

https://jwt.io allows you to decode, verify and generate JWT.

Usage #

Import #

import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';

Sign #

// Create a json web token
final jwt = JWT(
  {
    'id': 123,
    'server': {
      'id': '3e4fc296',
      'loc': 'euw-2',
    }
  },
  issuer: 'https://github.com/jonasroussel/jsonwebtoken',
);

// Sign it (default with HS256 algorithm)
token = jwt.sign(SecretKey('secret passphrase'));

print('Signed token: $token\n');

Verify #

try {
  // Verify a token
  final jwt = JWT.verify(token, SecretKey('secret passphrase'));

  print('Payload: ${jwt.payload}');
} on JWTExpiredError {
  print('jwt expired');
} on JWTError catch (ex) {
  print(ex.message); // ex: invalid signature
}

Supported Algorithms #

JWTAlgorithmDigital Signature or MAC Algorithm
HS256HMAC using SHA-256 hash algorithm
HS384HMAC using SHA-384 hash algorithm
HS512HMAC using SHA-512 hash algorithm
RS256RSASSA-PKCS1-v1_5 using SHA-256 hash algorithm
RS384RSASSA-PKCS1-v1_5 using SHA-384 hash algorithm
RS512RSASSA-PKCS1-v1_5 using SHA-512 hash algorithm
ES256ECDSA using P-256 curve and SHA-256 hash algorithm
ES384ECDSA using P-384 curve and SHA-384 hash algorithm
ES512ECDSA using P-521 curve and SHA-512 hash algorithm
EdDSAEdDSA using edwards25519 curve and SHA-512 hash algorithm
25
likes
130
pub points
89%
popularity

Publisher

jroussel.fr

A dart implementation of the famous javascript library 'jsonwebtoken' (JWT).

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

crypto, ed25519_edwards, pointycastle

More

Packages that depend on dart_jsonwebtoken