Skip to content

compwright/axios-oauth-client

Repository files navigation

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

importaxiosfrom'axios'import{authorizationCode}from'axios-oauth-client'constgetAuthorizationCode=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)constauth=awaitgetAuthorizationCode('AUTHORIZATION_CODE','OPTIONAL_SCOPES')// =>{"access_token": "...", "expires_in": 900, ... }

Owner Credentials grant

importaxiosfrom'axios'import{ownerCredentials}from'axios-oauth-client'constgetOwnerCredentials=ownerCredentials(axios.create(),'https://oauth.com/2.0/token',// OAuth 2.0 token endpoint'CLIENT_ID','CLIENT_SECRET')constauth=awaitgetOwnerCredentials('USERNAME','PASSWORD','OPTIONAL_SCOPES')// =>{"access_token": "...", "expires_in": 900, ... }

Client Credentials grant

importaxiosfrom'axios'import{clientCredentials}from'axios-oauth-client'constgetClientCredentials=clientCredentials(axios.create(),'https://oauth.com/2.0/token','CLIENT_ID','CLIENT_SECRET')constauth=awaitgetClientCredentials('OPTIONAL_SCOPES')// =>{"access_token": "...", "expires_in": 900, ... }

Refresh Token grant

importaxiosfrom'axios'import{refreshToken}from'axios-oauth-client'constgetRefreshToken=refreshToken(axios.create(),'https://oauth.com/2.0/token','CLIENT_ID','CLIENT_SECRET')constauth=awaitgetRefreshToken('REFRESH_TOKEN','OPTIONAL_SCOPES')// =>{"access_token": "...", "refresh_token": "...", "expires_in": 900, ... }

License

MIT

About

OAuth 2.0 client utils for axios

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 6