jwt-bearer-client-auth
Create and verify JWT bearer client assertions from the oauth-jwt-bearer RFC
Last updated 6 months ago by awlayton .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install jwt-bearer-client-auth 
SYNC missed versions from official npm registry.

Build Status Coverage Status Dependency Status License

jwt-bearer-client-auth

Create and verify RS256 based JWT oauth-jwt-bearer client authentications.

Installation

npm install jwt-bearer-client-auth

Require Usage

var clientAuth = require('jwt-bearer-client-auth');

API

generate(key, issuer, clientId, tokenEndpoint, expiresIn, options)

Generate a valid jwt-bearer client assertion from client details and the client's private RSA256 key.

Parameters

key {PEM JWK} The key used to sign the assertion. Currentlt the only supported key type is "PEM JWK". If the JWK has a kid property it will be included in the client assertion header.

issuer {String} An "unique identifier for the entity that issued the JWT." A good choice for a client generating assertions on-the-fly might be the client's OAuth 2.0 client ID.

clientId {String} The client's OAuth 2.0 client ID. It is the required value for the JWT's sub claim.

tokenEndpoint {String} The OAuth 2.0 authorization server's token endpoint. It is the required value for the JWT's aud claim.

expiresIn {Number} The number of seconds from now in which the client assertion expires.

options {Object} The options parameter is passed directly to [node-jsonwebtoken][auth0/node-jsonwebtoken]. This module will not allow the caller to override the properties required by the jwt-bearer RFC. You can add properties to the header and claim set with the following sub-objects:

  • header {Object} The properties of this object will be included in the JWT's header.
  • payload {Object} The properties of this object will be included in the JWT's claim body.

Usage Example

// Generate a jwt-bearer client assertion
var fs = require('fs');

var key = {
  kid: 'abc123',
  kty: 'PEM',
  pem: fs.readFileSync('abc123.private.pem')
};
var issuer = 'aksdfj2w3';
var clientId = 'ocjvS38kjxfa3JFXal342';
var tokenEndpoint = 'https://api.example.org/token';
var expiresIn = 60;
var options = {
  payload: {
    jti: 'zkjfa3i13'
  }
};

var assertion = clientAuth.generate(key, issuer, clientId, tokenEndpoint,
  expiresIn, options);

verify(token, hint, issuer, clientId, tokenEndpoint, options, [cb])

Verify the given assertion is a valid jwt-bearer client assertion.

Returned Value

A payload promise is returned, but a traditional function(err, valid) callback is also supported.

Parameters

token {JWT} The token which is being verified as a valid jwt-bearer client assertion.

hint {JWK/JWKS/JWK URI/false} This is passed directly to the jwks-utils jwkForSignature method. It can be:

  • The JWK for the token
  • A JWKS which the tokens JWK is stored in (by key id, kid)
  • A URI for a JWKS which the tokens JWK is stored in (by key id, kid)
  • Or, false, indicating that the key is stored within the token's header under either the jwk or jku property (note this can be easily be spoofed and the key should be verfied by other means before trusting it).

issuer {String} An "unique identifier for the entity that issued the JWT." A good choice for a client generating assertions on-the-fly might be the client's OAuth 2.0 client ID.

clientId {String} The client's OAuth 2.0 client ID. It is the required value for the JWT's sub claim.

tokenEndpoint {String} The OAuth 2.0 authorization server's token endpoint. It is the required value for the JWT's aud claim.

options {Object} The options parameter is used to customize the verification of the client assertion. The properties of this object are:

  • payload {Object} Extra payload claims (and acceptable values) the caller is requiring to be included in the token in order to verify the assertion.

cb {Function} The cb(err, payload) function can be used instead of the returned promise in the typical node fashion.

Usage Example

// Verify a jwt-bearer-client-auth client assertion
var assertion = getClientAssertion();
var key = getPublicKey();
var issuer = getIssuer();
var clientId = getClientId();
var tokenEndpoint = getTokenEndpoint();
var options = {
  jti: 'xjkaf3xz'
};

clientAuth
  .verify(assertion, key, issuer, clientId, tokenEndpoint, options)
  .then(function(payload) {
    console.log('Client assertion validated');
  })
  .catch(function(err) {
    console.log('Client assertion was not validated, because: ' + err);
  });
})

Current Tags

  • 1.0.0                                ...           latest (6 months ago)

7 Versions

  • 1.0.0                                ...           6 months ago
  • 0.4.0                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.1                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 1
Dependencies (5)
Dev Dependencies (20)

Copyright 2014 - 2016 © taobao.org |