json_web_token 0.1.3

  • README.md
  • Installing
  • Versions
  • 40

json_web_token

Json Web Token

Using OAuth 2.0 for Server to Server Applications

https://developers.google.com/accounts/docs/OAuth2ServiceAccount

openssl pkcs12 -in privatekey.p12 -nocerts -passin pass:notasecret -nodes -out rsa_private_key.pem

String iss = "[your_id]@developer.gserviceaccount.com";
String scopes = "https://www.googleapis.com/auth/devstorage.read_only";
String rsa_private_key_file = "rsa_private_key.pem";

test('test 1' , (){
      JWT jwt = new JWT(iss, scopes);
      var pemkey = new File(rsa_private_key_file).readAsStringSync();
      rsa_pkcs.RSAPKCSParser parser = new rsa_pkcs.RSAPKCSParser();
      rsa_pkcs.RSAPrivateKey pk = parser.parsePEM(pemkey).private;
      var privk = new RSAPrivateKey(pk.modulus, pk.privateExponent, pk.prime1, pk.prime2);
      
      return jwt.generateAuthUsingKey(privk).then((_){
        print(jwt.auth["access_token"]);
      });
    });
    
    test('test 2' , (){
      JWTStore.getCurrent().registerKey(iss, rsa_private_key_file);
     return  JWTStore.getCurrent().generateJWT(iss, scopes).then((JWT jwt){
        print(jwt.auth);
        print(jwt.isExpired);
      });
    });

once a token is generated it can be used with google api ...

import "package:google_analytics_v3_api/analytics_v3_api_console.dart";

Analytics analyticsClient = new Analytics(new oauth2.SimpleOAuth2Console(project, "", jwt.accessToken));
analyticsClient.makeAuthRequests = true;
...
...

1. Depend on it

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


dependencies:
  json_web_token: "^0.1.3"

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 packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:json_web_token/json_web_token.dart';
        
Version Uploaded Documentation Archive
0.1.3 Apr 12, 2014 Go to the documentation of json_web_token 0.1.3 Download json_web_token 0.1.3 archive
0.1.1 Mar 28, 2014 Go to the documentation of json_web_token 0.1.1 Download json_web_token 0.1.1 archive
0.1.0 Mar 15, 2014 Go to the documentation of json_web_token 0.1.0 Download json_web_token 0.1.0 archive

Analysis

This feature is new.
We welcome feedback.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Dec 6, 2017
  • Dart: 2.0.0-dev.8.0
  • pana: 0.7.3+1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
37
Health:
Code health derived from static analysis. [more]
73
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall score:
Weighted score of the above. [more]
40

Platforms

Detected platforms: Flutter, server

all of the above

Suggestions

  • Fix lib/src/JWT.dart.

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

    line: 153 col: 16
    The return type 'List' isn't a 'FutureOr<List<int>>', as defined by the method ''.

  • Maintain CHANGELOG.md.

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
cipher >=0.7.0 <0.8.0 0.7.1
crypto >=0.9.0 <0.10.0 0.9.2+1 2.0.2+1
rsa_pkcs >=0.1.1 <0.2.0 0.1.1 0.1.2
Transitive dependencies
asn1lib 0.3.5 0.4.2
bignum 0.0.7 0.1.0
charcode 1.1.1
convert 1.1.1 2.0.1
fixnum 0.9.1+2 0.10.6
typed_data 1.1.5
Dev dependencies
unittest any