2.0.4 • Published 6 months ago
axios-oauth-client v2.0.4
axios-oauth-client
OAuth 2.0 client utils for axios
Installation
With NPM:
$ npm install --save axios-oauth-client axios
With Yarn:
$ yarn add axios-oauth-client axios
Axios OAuth 2.0 Client
Authorization Code grant
import axios from 'axios'
import oauth from 'axios-oauth-client'
const getAuthorizationCode = oauth.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
import axios from 'axios'
import oauth from 'axios-oauth-client'
const getOwnerCredentials = oauth.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
import axios from 'axios'
import oauth from 'axios-oauth-client'
const getClientCredentials = oauth.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
import axios from 'axios'
import oauth from 'axios-oauth-client'
const getRefreshToken = oauth.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
2.0.3
8 months ago
2.0.4
6 months ago
2.0.2
1 year ago
2.0.1
1 year ago
2.0.0
2 years ago
1.5.0
2 years ago
1.4.4
3 years ago
1.4.3
3 years ago
1.4.2
3 years ago
1.4.1
3 years ago
1.4.0
3 years ago
1.3.0
4 years ago
1.2.3
4 years ago
1.2.2
4 years ago
1.2.1
5 years ago
1.2.0
5 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.0.0
6 years ago