Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@scienta/axios-oauth2

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scienta/axios-oauth2

Cacheable token interceptor for oauth requests with axios

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
676
increased by9.03%
Maintainers
3
Weekly downloads
 
Created
Source

axios-oauth2

This library makes oauth with axios easy. There is a oauth-client, a token interceptor and caching.

Quickstart

You can use only the client, or combine it with the token interceptor and caching.

Simple client usage

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

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

Client usage with interceptor

import axios from 'axios';
import {clientFactory, interceptorFactory} from '@scienta/axios-oauth';
const axiosInstance = axios.create();
axiosInstance.interceptors.request.use(
  interceptorFactory(clientFactory(axiosInstance, {
    url: 'https://oauth.com/2.0/token',
    grant_type: 'client_credentials',
    client_id: 'foo',
    client_secret: 'bar',
    scope: 'baz'
  }))
);
axiosInstance.get('https://oauth.com/2.0/protectedResource')

Client usage with token-caching interceptor

import axios from 'axios';
import {clientFactory, interceptorFactory, LockingTokenCache} from '@scienta/axios-oauth';

const axiosInstance = axios.create();
axiosInstance.interceptors.request.use(
  interceptorFactory(
    clientFactory(axiosInstance, {
      url: 'https://oauth.com/2.0/token',
      grant_type: 'client_credentials',
      client_id: 'foo',
      client_secret: 'bar',
      scope: 'baz'
    }),
    new LockingTokenCache()
  )
);

axiosInstance.get('https://oauth.com/2.0/protectedResource')

Locking cache (used by LockingTokenCache)

The LockingTokenCache class uses a separate library for locking and caching. Locking cache is a caching-library suited for simple and complex locking while caching. Locking with caching ensures that only one request is executed to request a token. Want to know more? @scienta/locking-cache.

FAQs

Package last updated on 14 Apr 2021

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