json_web_token 0.1.3

jsonwebtoken

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 rsaprivatekey.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:

$ pub get

Alternatively, your editor might support pub. 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';

About

Json Web Token

Author

Email alexandre.maurel@gmail.com Alexandre Maurel

Homepage

github.com/amaurel/json_web_token

Documentation

www.dartdocs.org/documentation/json_web_token/0.1.3/index.html#json_web_token

Uploader

alexandre.maurel@gmail.com

Share