Giter Site home page Giter Site logo

oauth2orize-jwt-bearer's Introduction

oauth2orize-jwt-bearer

JSON Web Token (JWT) Bearer Token Exchange Middleware for OAuth2orize.

This module exchanges a JWT for an access token after authenticated, as defined by the JSON Web Token (JWT) Bearer Token Profiles for OAuth 2.0 draft. This module is modeled off of Google's OAuth 2.0 Server to Server Applications. This module can be used with the passport-oauth2-jwt-bearer module to create a JWT OAuth 2.0 exchange scenario server.

Install

$ npm install oauth2orize-jwt-bearer

Usage

Register Exchange Middleware

This exchange middleware is used to by clients to request an access token by using a JSON Web Token (JWT) generated by the client and verified by a Public Key stored on the OAuth 2.0 server. The exchange requires a verify callback, which accepts the client, JWT data and signature, then calls done providing a access token.

var jwtBearer = require('oauth2orize-jwt-bearer').Exchange;

server.exchange('urn:ietf:params:oauth:grant-type:jwt-bearer', jwtBearer(function(client, data, signature, done) {
 var crypto = require('crypto')
   , pub = pubKey // TODO - Load your pubKey registered to the client from the file system or database
   , verifier = crypto.createVerify("RSA-SHA256");

 verifier.update(JSON.stringify(data));

 if (verifier.verify(pub, signature, 'base64')) {

   // TODO - base64url decode data then verify client_id, scope and expiration are valid

   AccessToken.create(client, scope, function(err, accessToken) {
     if (err) { return done(err); }
     done(null, accessToken);
   });
 }
}));

Tests

$ npm install --dev
$ make test

Credits

License

The MIT License

Copyright (c) 2012-2013 xTuple <http://www.xtuple.com/>

oauth2orize-jwt-bearer's People

Contributors

bendiy avatar shackbarth avatar

Watchers

 avatar  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.