just_jwt 1.3.1

  • README.md
  • Installing
  • Versions
  • 14

JustJWT #

Build Status

A simple JWT library for Dart with support for custom signature algorithms.

Library already supports HS256 and RS256 algorithms.

Usage #

A simple encoding example:

import 'dart:async';
import 'package:just_jwt/just_jwt.dart';

main() async {
  var signers = {
    'HS256': toTokenSigner(createHS256Signer('secret')),
    'RS256': toTokenSigner(createRS256Signer('<private key>')),
    // additional supported algorithms
  // Creates JWT encoder which supports ONLY tokens with HS256 or RS256 alg.
  var encoder = new Encoder(composeTokenSigners(signers));
  var jwt = new Jwt.HS256({'some': 'value'});
  // or var jwt = new Jwt.RS256({'some': 'value'});
  // Encodes JWT
  var encodedJwt = await encoder.convert(jwt);

A simple decoding example:

import 'package:just_jwt/just_jwt.dart';

main() async {
  var verifiers = {
    'HS256': toTokenVerifier(createHS256Verifier('secret')),
    'RS256': toTokenVerifier(createRS256Verifier('<public key>')),
    // additional supported algorithms
  // Creates decoder which support ONLY tokens with HS256 or RS256 alg.
  // Unsupported algorithm will cause an UnsupportedVerificationAlgError.
  var decoder = new Decoder(composeTokenVerifiers(verifiers));
  var encodedJwt = new EncodedJwt('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoidmFsdWUifQ==.ZHaHisAt9O9fcGFAFanEvsRjlSqAELN7NdXvue-E1PQ=');
  var jwt = await decoder.convert(encodedJwt);

Functional approach #

Each Verifier and Signer is a function.

As you can see in code example, there are a functions like toTokenSigner, toTokenVerifier, composeTokenVerifiers, etc. These functions provide a way how to compose a verifiers and signers.

Also, you can combine a multiple TokenVerifiers into one TokenVerifier with combineTokenVerifiers function:

  var algorithmVerifier = toTokenVerifier(createHS256Verifier('secret'));
  var expirationVerifier = (ToVerify toVerify) async =>  // check token expiration
  var verifier = combineTokenVerifiers([algorithmVerifier, expirationVerifier]);
  var decoder = new Decoder(verifier);

Custom algorithm #

Algorithm name is always stored in JWT. Encoders/Decoders tries to find a Signer/Verifier by its name in signers/verifiers map.

To support custom algorithm, just implement a JWT interface and create your own Signer/Verifier.

Changelog #

1.0.0 #

  • Initial version

1.1.0 #

  • Signer/Verifier works with List instead of String.

1.1.1 #

  • Works with non-padded BASE64 strings.

1.2.1 #

  • Improved Signers/Verifiers composition.
  • New createJwaRS256Verifier function which creates a RSA256 verifier from encoded modulus and encoded exponent as described in RFC 7518.

1.3.0 #

  • Changed JWT's header type from Map<String, String> to Map<String, dynamic>.
  • TokenVerifier and TokenSigner returns Future now.

1.3.1 #

  • Errors contain an instance of ToVerify / ToSign class.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  just_jwt: ^1.3.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:just_jwt/just_jwt.dart';
Version Uploaded Documentation Archive
1.3.1 Nov 5, 2016 Go to the documentation of just_jwt 1.3.1 Download just_jwt 1.3.1 archive
1.3.0 Oct 30, 2016 Go to the documentation of just_jwt 1.3.0 Download just_jwt 1.3.0 archive
1.2.1 Oct 21, 2016 Go to the documentation of just_jwt 1.2.1 Download just_jwt 1.2.1 archive
1.2.0 Oct 21, 2016 Go to the documentation of just_jwt 1.2.0 Download just_jwt 1.2.0 archive
1.1.1 Oct 21, 2016 Go to the documentation of just_jwt 1.1.1 Download just_jwt 1.1.1 archive
1.1.0 Sep 26, 2016 Go to the documentation of just_jwt 1.1.0 Download just_jwt 1.1.0 archive
1.0.0 Sep 25, 2016 Go to the documentation of just_jwt 1.0.0 Download just_jwt 1.0.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.16.0 <2.0.0