Skip to content

Library to introspect token of service following RFC-7662

Notifications You must be signed in to change notification settings

Stitch-Money/node-token-introspection

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-token-introspection

Node token introspection package introspects a token towards an oauth service that follows the RFC 7662.

Install

npm install token-introspection --save

Node version

Currently we only support latest Node LTS. If you want to use an earlier version of node, please use babel register.

Usage

Introspect package is configured with endpoint and client credentials, and a function is returned. Calling that function with token, and optional token_type_hint will return a Promise.

const tokenIntrospection = require('token-introspection')({
    endpoint: 'https://example.com/introspect',
    client_id: '<Client ID>',
    client_secret: '<Client Secret>',
});

tokenIntrospection(token).then(console.log).catch(console.warn);

Configuration

Field Required Comment
jwks (X) Static JWKS of trusted keys, for example {keys: [{kty:'RSA',n:'4-4mhUVhY2k',e:'AQAB'}]}
jwks_uri (X) URL of a trusted JWKS, for example https://example.com/jwks
endpoint (X) URL to call, for instance https://example.com/introspect
allowed_algs List of allowed signing algorithms, defaults to ['RS256']
jwks_cache_enabled If jwks response should be cached, defaults to true
jwks_cache_maxentries How many jwk's to cache, defaults to 10
jwks_cache_time How long a jwk is cached, in ms, defaults to 5 min
jwks_ratelimit_enabled If ratelimit of calls to jwks endpoint, defaults to true
jwks_ratelimit_per_minute Limits of jwks calls, defaults to 60 rpm
client_id Client ID used to introspect
client_secret Client secret used to introspect
access_token Access token used to introspect, instead of client credentials
user_agent Defaults to token-introspection
proxy Optional url with port to proxy request through. Requires optional dependency https-proxy-agent
fetch Defaults to node-fetch, but you can inject zipkin-instrumentation-fetch.

At least one of the required configuration parameters jwks, jwks_uri or endpoint must be specified.

Errors

This is a promise/async library, and will resolve with success or reject with an Error subclass.

  • IntrospectionError: Base error, thrown when introspection fails for some reason.
  • ConfigurationError: Thrown when configuration is wrong.
  • MalformedTokenError: Thrown when token is malformed, currently not publicly exposed.
  • TokenNotActiveError: Thrown when token is not active, base error for TokenExpiredError and NotBeforeError.
  • TokenExpiredError: Thrown in local introspection when token has expired.
  • NotBeforeError: Thrown in local introspection when token is not yet valid

Showing debug output

Set the environment variable DEBUG=token-introspection.

About

Library to introspect token of service following RFC-7662

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%