Giter Club home page Giter Club logo

jwt's Introduction

jwt

Apex implementation of JWT and JWT Bearer flow. Requires Summer 14 release for RSA-SHA256 support.

#Unsigned JWT

JWT jwt = new JWT('none');
jwt.iss = 'your issuer';
jwt.sub = 'some subject';
jwt.aud = 'some audience';
token = jwt.issue();

#HMAC256 Signed JWT

JWT jwt = new JWT('HS256');
jwt.privateKey = 'base64 encoded secret';
jwt.iss = 'your issuer';
jwt.sub = 'some subject';
jwt.aud = 'some audience';
token = jwt.issue();        

#RSA256 Signed JWT with PEM encoded p12

JWT jwt = new JWT('RS256');
jwt.pem = 'MIICXQIBAAKBgQC4U4Bma7kKa0CLU...pem encoded p12 RSA Key';
jwt.iss = 'your issuer';
jwt.sub = 'some subject';
jwt.aud = 'some audience';
token = jwt.issue();     

#RSA256 Signed JWT with Certificate from Setup

JWT jwt = new JWT('RS256');
jwt.cert = 'JWTKey';
jwt.iss = 'your issuer';
jwt.sub = 'some subject';
jwt.aud = 'some audience';
token = jwt.issue();     

#Change the default expiration By default expiration is 5 minutes (300 seconds). Change it by passing in a validFor in seconds.

JWT jwt = new JWT('none');
jwt.validFor = 60;

#Bearer Flow Use the JWT bearer flow for Server to Server applications.

JWTBearerFlow.getAccessToken('token_endpoint', jwt);

#Salesforce RSA-256 JWT Bearer Flow [http://help.salesforce.com/HTViewHelpDoc?id=remoteaccess_oauth_jwt_flow.htm&language=en_US]

JWT jwt = new JWT('RS256');
jwt.cert = 'JWTKey';
jwt.iss = '3MVG9PhR6g6B7ps6TYoM9J8TuRwyvkAmDUKainDupyG6eJ92nmK8m4LYueD5Lgtnyv0QoWBrB.YjuWCVj_rl_';
jwt.sub = '[email protected]';
jwt.aud = 'https://login.salesforce.com/services/oauth2/token';
String access_token = JWTBearerFlow.getAccessToken('https://login.salesforce.com/services/oauth2/token', jwt);

#Google RSA-256 JWT Bearer Flow [https://developers.google.com/accounts/docs/OAuth2ServiceAccount]

JWT jwt = new JWT('RS256');
jwt.pem = 'MIICXQIBAAKBgQC4U4Bma7kKa0CLU...pem encoded p12 RSA Key';
jwt.iss = '[email protected]';
jwt.sub = '[email protected]';
jwt.aud = 'https://accounts.google.com/o/oauth2/token';
Map<String,String> claims = new  Map<String,String>();
claims.put('scope','https://www.googleapis.com/auth/drive');
jwt.claims = claims;
String access_token = JWTBearerFlow.getAccessToken('https://accounts.google.com/o/oauth2/token', jwt);

jwt's People

Contributors

cmortimore avatar

Watchers

vinayak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.