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 { authorizationCode } from 'axios-oauth-client'
const getAuthorizationCode = authorizationCode(
axios.create(),
'https://oauth.com/2.0/token',
'CLIENT_ID',
'CLIENT_SECRET',
'https://your-app.com/oauth-redirect'
)
const auth = await getAuthorizationCode('AUTHORIZATION_CODE', 'OPTIONAL_SCOPES')
Owner Credentials grant
import axios from 'axios'
import { ownerCredentials } from 'axios-oauth-client'
const getOwnerCredentials = ownerCredentials(
axios.create(),
'https://oauth.com/2.0/token',
'CLIENT_ID',
'CLIENT_SECRET'
)
const auth = await getOwnerCredentials('USERNAME', 'PASSWORD', 'OPTIONAL_SCOPES')
Client Credentials grant
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')
Refresh Token grant
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')
License
MIT