just_jwt 1.3.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 69

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);
  print(encodedJwt);
}

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:


dependencies:
  just_jwt: "^1.3.1"

2. Install it

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 flutter packages 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

Analysis

We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
68 / 100
Health:
Code health derived from static analysis. [more]
91 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
38 / 100
Overall score:
Weighted score of the above. [more]
69
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:just_jwt/just_jwt.dart.

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 error 12 hints.

    Strong-mode analysis of lib/src/algorithms/rs256.dart failed with the following error:

    line: 34 col: 46
    The getter 'bytes' isn't defined for the class 'Signature'.

    Run dartfmt to format lib/src/tokens/decoder.dart.

    Similar analysis of the following files failed:

    • lib/src/tokens/encoded_jwt.dart (hint)
    • lib/src/tokens/encoder.dart (hint)
    • lib/src/tokens/jwt.dart (hint)
    • lib/src/tokens/signers.dart (hint)
    • lib/src/tokens/verifiers.dart (hint)
  • Package is getting outdated.

    The package was released 84 weeks ago.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use just_jwt.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.16.0 <2.0.0
collection ^1.9.1 1.14.10
crypto ^2.0.1 2.0.5
pointycastle ^0.10.0 0.10.0+5 0.11.1
rsa_pkcs ^0.1.2 0.1.2
Transitive dependencies
analyzer 0.30.0+4 0.32.1
args 1.4.3
asn1lib 0.4.3 0.5.0
async 2.0.7
barback 0.15.2+16
bignum 0.1.0
charcode 1.1.1
cli_util 0.1.3
code_transformers 0.5.1+5
convert 2.0.1
csslib 0.14.4
dart_style 1.0.9+1 1.1.0
fixnum 0.10.7
front_end 0.1.0-alpha.4.1 0.1.1
glob 1.1.5
html 0.13.3+1
isolate 1.1.0 2.0.1
kernel 0.3.0-alpha.1.1 0.3.1
logging 0.11.3+1
meta 1.1.5
package_config 1.0.3
path 1.4.2 1.6.1
plugin 0.2.0+2
pool 1.3.5
quiver_collection 1.0.0
quiver_iterables 1.0.1
quiver_pattern 1.0.0
reflectable 1.0.4 2.0.1
source_maps 0.10.5
source_span 1.4.0
stack_trace 1.9.2
string_scanner 1.0.2
typed_data 1.1.5
utf 0.9.0+4
watcher 0.9.7+8
yaml 2.1.14
Dev dependencies
test ^0.12.15