Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/platformatic/undici-oidc-interceptor
https://github.com/platformatic/undici-oidc-interceptor
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/platformatic/undici-oidc-interceptor
- Owner: platformatic
- License: mit
- Created: 2023-11-17T21:03:15.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-25T19:45:48.000Z (5 months ago)
- Last Synced: 2024-07-25T22:42:52.696Z (5 months ago)
- Language: JavaScript
- Size: 1000 KB
- Stars: 3
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# undici-oidc-interceptor
[![NPM version](https://img.shields.io/npm/v/undici-oidc-interceptor.svg?style=flat)](https://www.npmjs.com/package/undici-oidc-interceptor)
`undici-oidc-interceptor` manages an [OIDC](https://openid.net/specs/openid-connect-core-1_0.html) 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
```bash
npm i undici undici-oidc-interceptor
```## Usage with client credentials
```js
const { Agent } = require('undici')
const { createOidcInterceptor } = require('undici-oidc-interceptor')
const dispatcher = new Agent({
interceptors: {
Pool: [createOidcInterceptor({
// 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 array of urls that this interceptor will be appending `Authorization` header
// for automatically
urls: ['FILLME'],// OPTIONAL: an initial access token
accessToken: ''
})]
}
})
```## Usage with refresh token
```js
const { Agent } = require('undici')
const { createOidcInterceptor } = require('undici-oidc-interceptor')
const dispatcher = new Agent({
interceptors: {
Pool: [createOidcInterceptor({
// 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 array of urls that this interceptor will be appending `Authorization` header
// for automatically
urls: [],// OPTIONAL: an initial access token
accessToken: ''
})]
}
})
```## License
MIT