Jonas Roussel 76ba87d772 formating
2020-08-28 15:12:33 +02:00
2020-08-25 22:20:02 +02:00
2020-08-28 15:12:33 +02:00
2020-05-30 01:14:08 +02:00
2020-08-28 15:03:22 +02:00
2020-05-31 16:12:10 +02:00
2020-08-28 15:03:22 +02:00
2020-08-28 15:03:22 +02:00

JSON Web Token

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(
  payload: {
    '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

  • HS256 (HMAC / SHA256)

  • HS384 (HMAC / SHA384)

  • HS512 (HMAC / SHA512)

  • RS256 (RSA / SHA256)

  • RS384 (RSA / SHA384)

  • RS512 (RSA / SHA512)

Description
An easy to use JSON Web Token implementation in Dart (all algorithms supported).
Readme MIT 310 KiB
Languages
Dart 100%