undici-oidc-interceptor

0.5.0 • Public • Published

undici-oidc-interceptor

NPM version

undici-oidc-interceptor manages an OIDC access token and transparently sets the Authorization header on any request that is going to a limited set of domains.

The token is automatically renewed after it expires. It supports both a refresh_token and client_credentials grants.

Install

npm i undici undici-oidc-interceptor

Usage with client credentials

const { Agent } = require('undici')
const { createOAuthIntercpetor } = require('undici-oidc-interceptor')
const dispatcher = new Agent({
  intercpetors: {
    Pool: [createOAuthIntercpetor({
      // The paramerts for the cliend_credentials grant of OIDC
      clientId: 'FILLME',
      clientSecret: 'FILLME',
      idpTokenUrl: 'https://your-idp.com/token',

      // Set an array of status codes that the interceptor should refresh and
      // retry the request on
      retryOnStatusCodes: [401],

      // The origins that this interceptor will add the `Authorization` header
      // automatically
      origins: ['FILLME']

      // OPTIONAL: an initial access token
      accessToken: ''
    })]
  }
})

Usage with refresh token

const { Agent } = require('undici')
const { createOAuthIntercpetor } = require('undici-oidc-interceptor')
const dispatcher = new Agent({
  intercpetors: {
    Pool: [createOAuthIntercpetor({
      // Provide a refresh token so the interceptor can manage the access token
      // The refresh token must include an issuer (`iss`)
      refreshToken: '',
      idpTokenUrl: 'https://your-idp.com/token',
      clientId: 'FILLME',

      // Set an array of status codes that the interceptor should refresh and
      // retry the request on
      retryOnStatusCodes: [401],

      // The origins that this interceptor will add the `Authorization` header
      // automatically
      origins: []

      // OPTIONAL: an initial access token
      accessToken: ''
    })]
  }
})

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i undici-oidc-interceptor

Weekly Downloads

766

Version

0.5.0

License

MIT

Unpacked Size

52.9 kB

Total Files

14

Last publish

Collaborators

  • matteo.collina