Socket
Socket
Sign inDemoInstall

axios-oauth-client

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-oauth-client

OAuth 2.0 client utils for axios


Version published
Weekly downloads
67K
increased by0.9%
Maintainers
1
Weekly downloads
 
Created
Source

axios-oauth-client

Build Status Greenkeeper badge

OAuth 2.0 client utils for axios

Installation

$ npm install --save axios-oauth-client axios-token-interceptor axios

Axios OAuth 2.0 Client

Authorization Code grant

const axios = require('axios');
const oauth = require('axios-oauth-client');
const getAuthorizationCode = oauth.client(axios.create(), {
  url: 'https://oauth.com/2.0/token',
  grant_type: 'authorization_code',
  client_id: 'foo',
  client_secret: 'bar',
  redirect_uri: '...',
  code: '...',
  scope: 'baz',
});

const auth = await getAuthorizationCode(); // => { "access_token": "...", "expires_in": 900, ... }

Owner Credentials grant

const axios = require('axios');
const oauth = require('axios-oauth-client');
const getOwnerCredentials = oauth.client(axios.create(), {
  url: 'https://oauth.com/2.0/token',
  grant_type: 'password',
  client_id: 'foo',
  client_secret: 'bar',
  username: 'asdf',
  password: 'yuio',
  scope: 'baz'
});

const auth = await getOwnerCredentials(); // => { "access_token": "...", "expires_in": 900, ... }

Client Credentials grant

const axios = require('axios');
const oauth = require('axios-oauth-client');
const getClientCredentials = oauth.client(axios.create(), {
  url: 'https://oauth.com/2.0/token',
  grant_type: 'client_credentials',
  client_id: 'foo',
  client_secret: 'bar',
  scope: 'baz'
});

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

Refresh Token grant

const axios = require('axios');
const oauth = require('axios-oauth-client');
const getRefreshToken = oauth.client(axios.create(), {
  url: 'https://oauth.com/2.0/token',
  grant_type: 'refresh_token',
  client_id: 'foo',
  client_secret: 'bar',
  refresh_token: '...',
  scope: 'baz'
});

const auth = await getRefreshToken(); // => { "access_token": "...", "refresh_token": "...", "expires_in": 900, ... }

Axios OAuth 2.0 Authentication interceptor

const axios = require('axios');
const oauth = require('axios-oauth-client');
const tokenProvider = require('axios-token-interceptor');

const getOwnerCredentials = oauth.client(axios.create(), {
  // see example above
})

const instance = axios.create();
instance.interceptors.request.use(
  // Wraps axios-token-interceptor with oauth-specific configuration,
  // fetches the token using the desired claim method, and caches
  // until the token expires
  oauth.interceptor(tokenProvider, getOwnerCredentials)
);

License

MIT

Keywords

FAQs

Package last updated on 24 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc