Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/compwright/axios-oauth-client
OAuth 2.0 client utils for axios
https://github.com/compwright/axios-oauth-client
axios interceptor oauth2
Last synced: about 3 hours ago
JSON representation
OAuth 2.0 client utils for axios
- Host: GitHub
- URL: https://github.com/compwright/axios-oauth-client
- Owner: compwright
- License: mit
- Created: 2018-09-22T01:29:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-02T17:37:03.000Z (about 1 month ago)
- Last Synced: 2024-11-01T20:12:24.754Z (6 days ago)
- Topics: axios, interceptor, oauth2
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/axios-oauth-client
- Size: 1.23 MB
- Stars: 70
- Watchers: 3
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
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