jwt 0.1.4

  • README.md
  • Installing
  • Versions
  • 30

JSON Web Token

JSON Web Token (JWT) is a compact URL-safe means of representing claims to be transferred between two parties. The claims in a JWT are encoded as a JavaScript Object Notation (JSON) object that is used as the payload of a JSON Web Signature (JWS) structure or as the plaintext of a JSON Web Encryption (JWE) structure, enabling the claims to be digitally signed or MACed and/or encrypted.

The JWT spec is implemented as a standard Dart Codec.

Example usage

import 'package:jwt/json_web_token.dart';

// Encode (i.e. sign) a payload into a JWT token.

final jwt = new JsonWebTokenCodec(secret: "My secret key");
final payload = {
  'iss': 'joe',
  'exp': 1300819380,
  'http://example.com/is_root': true
};
final token = jwt.encode(payload);

// Validate a token.

jwt.isValid(token);

// Decode (i.e. extract) the payload from a JWT token.

final payload = jwt.decode(token);

Status

The API is not stable. The intend is to strictly follow Dart conventions, i.e. make the API as 'dartish' as possible while maintaining simplicity. We are open to any suggestions towards that goal.

Credits

Copyright (c) 2014 George Moschovitis george.moschovitis@gmail.com.

Use this package as a library

1. Depend on it

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


dependencies:
  jwt: ^0.1.4

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:jwt/base64.dart';
import 'package:jwt/base64url.dart';
import 'package:jwt/json_web_signature.dart';
import 'package:jwt/json_web_token.dart';
  
Version Uploaded Documentation Archive
0.1.4 Mar 25, 2014 Go to the documentation of jwt 0.1.4 Download jwt 0.1.4 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
61
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
30
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.

Health issues and suggestions

Fix lib/json_web_signature.dart. (-90.04 points)

Analysis of lib/json_web_signature.dart failed with 8 errors, 1 hint, including:

line 19 col 3: 'JsonWebSignatureEncoder.convert' ('(List<int>, {header: Map<dynamic, dynamic>, secret: String}) → String') isn't a valid override of 'Converter.convert' ('(dynamic) → dynamic').

line 21 col 11: Undefined name 'JSON'.

line 22 col 37: Undefined name 'JSON'.

line 47 col 3: 'JsonWebSignatureDecoder.convert' ('(String, {secret: String}) → List<int>') isn't a valid override of 'Converter.convert' ('(dynamic) → dynamic').

line 80 col 3: 'JsonWebSignatureCodec.encode' ('(List<int>, {header: Map<dynamic, dynamic>, secret: String}) → String') isn't a valid override of 'Codec.encode' ('(dynamic) → dynamic').

Fix lib/json_web_token.dart. (-82.20 points)

Analysis of lib/json_web_token.dart failed with 6 errors, including:

line 19 col 3: 'JsonWebTokenEncoder.convert' ('(Map<dynamic, dynamic>, {header: Map<dynamic, dynamic>, secret: String}) → String') isn't a valid override of 'Converter.convert' ('(dynamic) → dynamic').

line 21 col 33: Undefined name 'JSON'.

line 36 col 3: 'JsonWebTokenDecoder.convert' ('(String, {header: Map<dynamic, dynamic>, secret: String}) → Map<dynamic, dynamic>') isn't a valid override of 'Converter.convert' ('(dynamic) → dynamic').

line 38 col 12: Undefined name 'JSON'.

line 65 col 3: 'JsonWebTokenCodec.encode' ('(Map<dynamic, dynamic>, {header: Map<dynamic, dynamic>, secret: String}) → String') isn't a valid override of 'Codec.encode' ('(dynamic) → dynamic').

Fix lib/base64.dart. (-68.52 points)

Analysis of lib/base64.dart failed with 4 errors, 1 hint:

line 18 col 3: 'Base64Encoder.convert' ('(List<int>) → String') isn't a valid override of 'Converter.convert' ('(dynamic) → dynamic').

line 19 col 38: Undefined name 'CryptoUtils'.

line 29 col 3: 'Base64Decoder.convert' ('(String) → List<int>') isn't a valid override of 'Converter.convert' ('(dynamic) → dynamic').

line 30 col 38: Undefined name 'CryptoUtils'.

line 9 col 8: Unused import: 'package:crypto/crypto.dart'.

Fix lib/base64url.dart. (-68.52 points)

Analysis of lib/base64url.dart failed with 4 errors, 1 hint:

line 28 col 3: 'Base64UrlEncoder.convert' ('(List<int>) → String') isn't a valid override of 'Converter.convert' ('(dynamic) → dynamic').

line 30 col 36: Undefined name 'CryptoUtils'.

line 51 col 3: 'Base64UrlDecoder.convert' ('(String) → List<int>') isn't a valid override of 'Converter.convert' ('(dynamic) → dynamic').

line 53 col 12: Undefined name 'CryptoUtils'.

line 12 col 8: Unused import: 'package:crypto/crypto.dart'.

Maintenance issues and suggestions

Add SDK constraint in pubspec.yaml. (-50 points)

For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Error(s) in lib/base64.dart: 'Base64Encoder.convert' ('(List<int>) → String') isn't a valid override of 'Converter.convert' ('(dynamic) → dynamic').

Running dartdoc failed. (-10 points)

Make sure dartdoc runs without any issues.

Package is too old. (-100 points)

The package was released more than two years ago.

Maintain CHANGELOG.md. (-20 points)

Changelog entries help clients to follow the progress in your code.

Use constrained dependencies. (-20 points)

The pubspec.yaml contains 1 dependency without version constraints. Specify version ranges for the following dependencies: crypto.

The description is too short. (-20 points)

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. (-10 points)

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 jwt.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
crypto any 2.0.6
Transitive dependencies
charcode 1.1.2
collection 1.14.11
convert 2.0.2
typed_data 1.1.6
Dev dependencies
unittest any