Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oauth2orize-jwt-bearer

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oauth2orize-jwt-bearer

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

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
199
increased by38.19%
Maintainers
3
Weekly downloads
 
Created
Source

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.

Key Generation Tips

generate private key openssl genrsa -out private.pem 1024

abstract public key openssl rsa -in private.pem -out public.pem -outform PEM -pubout

sign the data signing data: echo -n "data-to-sign" | openssl dgst -RSA-SHA256 -sign private.pem > signed

convert the signed file (binary) into base64 to be sent. base64 signed

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')
   , fs = require('fs') //load file system so you can grab the public key to read.
   , pub = fs.readFileSync('/path/to/public.pem').toString() //load PEM format public key as string, should be clients public key
   , verifier = crypto.createVerify("RSA-SHA256");

 //verifier.update takes in a string of the data that is encrypted in the signature  
 verifier.update(JSON.stringify(data));

 if (verifier.verify(pub, signature, 'base64')) {
   //base64url decode data 
   var b64string = data;
   var buf = new Buffer(b64string, 'base64').toString('ascii');
 
   // TODO - verify client_id, scope and expiration are valid from the buf variable above

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

Tests

$ npm install --dev
$ make test

Credits

  • bendiy

License

The MIT License

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

Keywords

FAQs

Package last updated on 13 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc