# axios-oauth-client

> OAuth 2.0 client utils for axios

Latest version **2.2.0** (published 2024-04-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install axios-oauth-client
pnpm add axios-oauth-client
yarn add axios-oauth-client
bun add axios-oauth-client
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2024-04-29 |
| First published | 2018-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 14 |
| Dependencies | 0 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 69 |
| Author | Jonathon Hill |
| Maintainers | compwright |
| Keywords | oauth, oauth2, axios, interceptor |

## Links

- npm: https://www.npmjs.com/package/axios-oauth-client
- Repository: https://github.com/compwright/axios-oauth-client
- Homepage: https://github.com/compwright/axios-oauth-client#readme
- Issues: https://github.com/compwright/axios-oauth-client/issues
- npm.io page: https://npm.io/package/axios-oauth-client

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2024-04-29
- 2.1.0 — 2024-04-28
- 2.0.4 — 2023-10-16
- 2.0.3 — 2023-09-13
- 2.0.2 — 2022-12-08
- 2.0.1 — 2022-12-07
- 2.0.0 — 2022-10-05
- 1.5.0 — 2022-05-24
- 1.4.4 — 2021-10-12
- 1.4.3 — 2021-07-06
- 1.4.2 — 2021-06-02
- 1.4.1 — 2021-05-12
- 1.4.0 — 2020-12-12
- 1.3.0 — 2020-04-14
- 1.2.3 — 2020-03-31
- … 6 more at https://npm.io/package/axios-oauth-client/versions

## README

# axios-oauth-client

OAuth 2.0 client utils for axios

## Installation

With NPM:

```bash
$ npm install --save axios-oauth-client axios
```

With Yarn:

```bash
$ yarn add axios-oauth-client axios
```

## Axios OAuth 2.0 Client

### Authorization Code grant

```javascript
import axios from 'axios'
import { authorizationCode } from 'axios-oauth-client'
const getAuthorizationCode = authorizationCode(
  axios.create(),
  'https://oauth.com/2.0/token', // OAuth 2.0 token endpoint
  'CLIENT_ID',
  'CLIENT_SECRET',
  'https://your-app.com/oauth-redirect' // Redirect URL for your app
)

const auth = await getAuthorizationCode('AUTHORIZATION_CODE', 'OPTIONAL_SCOPES')
// => { "access_token": "...", "expires_in": 900, ... }
```

### Owner Credentials grant

```javascript
import axios from 'axios'
import { ownerCredentials } from 'axios-oauth-client'
const getOwnerCredentials = ownerCredentials(
  axios.create(),
  'https://oauth.com/2.0/token', // OAuth 2.0 token endpoint
  'CLIENT_ID',
  'CLIENT_SECRET'
)

const auth = await getOwnerCredentials('USERNAME', 'PASSWORD', 'OPTIONAL_SCOPES')
// => { "access_token": "...", "expires_in": 900, ... }
```

### Client Credentials grant

```javascript
import axios from 'axios'
import { clientCredentials } from 'axios-oauth-client'
const getClientCredentials = clientCredentials(
  axios.create(),
  'https://oauth.com/2.0/token',
  'CLIENT_ID',
  'CLIENT_SECRET'
)

const auth = await getClientCredentials('OPTIONAL_SCOPES')
// => { "access_token": "...", "expires_in": 900, ... }
```

### Refresh Token grant

```javascript
import axios from 'axios'
import { refreshToken } from 'axios-oauth-client'
const getRefreshToken = refreshToken(
  axios.create(),
  'https://oauth.com/2.0/token',
  'CLIENT_ID',
  'CLIENT_SECRET'
)

const auth = await getRefreshToken('REFRESH_TOKEN', 'OPTIONAL_SCOPES')
// => { "access_token": "...", "refresh_token": "...", "expires_in": 900, ... }
```

## License

MIT

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