3.2.0 • Published 1 year ago

token-introspection v3.2.0

Weekly downloads
1,788
License
MIT
Repository
github
Last release
1 year ago

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

FieldRequiredComment
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_algsList of allowed signing algorithms, defaults to ['RS256']
jwks_cache_enabledIf jwks response should be cached, defaults to true
jwks_cache_maxentriesHow many jwk's to cache, defaults to 10
jwks_cache_timeHow long a jwk is cached, in ms, defaults to 5 min
jwks_timeoutTimeout in ms for fetching jwks, defaults to 10s
jwks_ratelimit_enabledIf ratelimit of calls to jwks endpoint, defaults to true
jwks_ratelimit_per_minuteLimits of jwks calls, defaults to 60 rpm
client_idClient ID used to introspect
client_secretClient secret used to introspect
access_tokenAccess token used to introspect, instead of client credentials
user_agentDefaults to token-introspection
fetchDefaults 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.

Flexibility in fetch

As you can provide your own fetch implementation, it is possible override the agent fetch uses for various purposes. These purpose can be things like zipkin/tracing, self signed certificates, client TLS authentication, proxy, adding a keepAlive, etc.

const HttpsProxy = require('https-proxy-agent');
const proxy = new HttpsProxy(proxySettings);

const customFetch = (endpoint, options) => {
    options.agent = proxy;
    process.env.HTTPS_PROXY = proxy;
    return fetch(endpoint, options);
};

const tokenIntrospection = require('token-introspection');
const introspector = tokenIntrospection({endpoint, ..., fetch: customFetch});

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.

3.2.0

1 year ago

3.1.1

1 year ago

3.1.0

2 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

5 years ago

1.2.0

5 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.0

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago