# undici-oauth-interceptor

> Automatically manage OAuth 2.0 access tokens for Undici requests

Latest version **0.4.2** (published 2024-02-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install undici-oauth-interceptor
pnpm add undici-oauth-interceptor
yarn add undici-oauth-interceptor
bun add undici-oauth-interceptor
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2024-02-04 |
| First published | 2023-12-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 30.8 KB |
| Known vulnerabilities | 0 (+10 in 1 direct dependencies) |
| Install scripts | no |
| Author | Platformatic |
| Maintainers | antoniosonis, mzugm, leorossi, marcopiraccini, ivan-tymoshenko, matteo.collina |

## Links

- npm: https://www.npmjs.com/package/undici-oauth-interceptor
- npm.io page: https://npm.io/package/undici-oauth-interceptor

## Dependencies (2)

- [undici](https://npm.io/package/undici.md) ^6.0.0
- [fast-jwt](https://npm.io/package/fast-jwt.md) ^3.3.2

## Recent versions

- 0.4.2 (latest) — 2024-02-04
- 0.4.1 — 2024-02-04
- 0.4.0 — 2024-02-02
- 0.3.0 — 2024-01-29
- 0.2.0 — 2023-12-07
- 0.1.0 — 2023-12-01

## README

# undici-oauth-interceptor

Manages an access token and automatically sets the `Authorization` header on any
request that is going to a limited set of domains.

## Install

```bash
npm i undici undici-oauth-interceptor
```

## Usage

```javascript
const { Agent } = require('undici')
const { createOAuthIntercpetor } = require('undici-oauth-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: '',

      // 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: ''

      // OPTIONAL: clientId that matches refresh token
      // Default: the `sub` claim in the refresh token
      clientId: null
    })]
  }
})
``` 

## License

MIT

---
_Source: https://npm.io/package/undici-oauth-interceptor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
