start_jwt 0.2.0

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:start_jwt/json_web_token.dart';

void main() {

    // 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);
    print ("Payload : " + payload.toString());
    
    // Validate a token.
    
    jwt.isValid(token);
    
    // Decode (i.e. extract) the payload from a JWT token.
    
    final decoded = jwt.decode(token);
    print ("Decoded : " + decoded.toString());
}

Status #

The API is very simple. 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.

Copyright (c) 2019 JarrodCColburn at https://github.com/JarrodCColburn.

Copyright (c) 2020 Benjamin Jung bsjung@gmail.com.

Use this package as a library

1. Depend on it

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


dependencies:
  start_jwt: ^0.2.0

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:start_jwt/base64.dart';
import 'package:start_jwt/base64url.dart';
import 'package:start_jwt/json_web_signature.dart';
import 'package:start_jwt/json_web_token.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
61
Health:
Code health derived from static analysis. [more]
64
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
52
Overall:
Weighted score of the above. [more]
60
Learn more about scoring.

We analyzed this package on Mar 30, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health issues and suggestions

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

Analysis of lib/base64.dart failed with 1 error, 5 hints, including:

line 29 col 13: 'Base64Decoder.convert' ('List

line 1 col 1: Prefer using /// for doc comments.

line 11 col 1: Prefer using /// for doc comments.

line 22 col 1: Prefer using /// for doc comments.

line 33 col 1: Prefer using /// for doc comments.

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

Analysis of lib/base64url.dart reported 13 hints, including:

line 1 col 1: Prefer using /// for doc comments.

line 14 col 16: Unnecessary new keyword.

line 15 col 18: Unnecessary new keyword.

line 16 col 19: Unnecessary new keyword.

line 17 col 19: Unnecessary new keyword.

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

Analysis of lib/json_web_token.dart reported 8 hints, including:

line 1 col 1: Prefer using /// for doc comments.

line 12 col 1: Prefer using /// for doc comments.

line 16 col 31: Avoid const keyword.

line 26 col 1: Prefer using /// for doc comments.

line 30 col 31: Avoid const keyword.

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

Analysis of lib/json_web_signature.dart reported 5 hints:

line 1 col 1: Prefer using /// for doc comments.

line 10 col 1: Prefer using /// for doc comments.

line 24 col 1: Prefer using /// for doc comments.

line 53 col 13: Unnecessary new keyword.

line 59 col 1: Prefer using /// for doc comments.

Maintenance issues and suggestions

No valid SDK. (-20 points)

The analysis could not detect a valid SDK that can use this package.

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

The package description is too short. (-8 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and start_jwt.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.65 <3.0.0
crypto ^2.1.4 2.1.4
cryptoutils ^0.4.0 0.4.0
Transitive dependencies
charcode 1.1.3
collection 1.14.12
convert 2.1.1
typed_data 1.1.6
Dev dependencies
test ^1.0.0