npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

token-introspection-es

v3.1.3

Published

Fork of token-introspect package to make it temporarily compatible with ES5 imports. Credits to Joakim Wånggren. :)

Downloads

9

Readme

node-token-introspection

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

This package is a fork from node-token-introspection by Joakim Wånggren to make it

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_timeout | | Timeout in ms for fetching jwks, defaults to 10s | | 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 | | 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.

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.