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

fetch-mw-oauth2

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-mw-oauth2

Fetch middleware to add OAuth2 support

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
increased by328.74%
Maintainers
1
Weekly downloads
 
Created
Source

fetch-mw-oauth2

This library adds support to OAuth2 to fetch by wrapping the fetch function. It works both for fetch() in a browser, as well as node-fetch.

Installation

npm i fetch-mw-oauth2

Usage

The fetch-mw-oauth2 package effectively works as follows:

  1. You pass it set up instructions
  2. It returns a new fetch()-like function.

This new fetch() function can now be used in place of the regular fetch, but it takes responsibility of oauth2 authentication.

const fetchMwOauth2 = require('fetch-mw-oauth2');

const newFetch = fetchMwOAuth2({
  clientId: '...',
  clientSecret: '...',
  grantType: 'client_credentials',
  authorizationUri: 'https://github.com/login/oauth/authorize',
  scopes: ['foo', 'bar'],
});

const response = await newFetch('https://api.example.org');

Project status

The current features have been implemented:

  1. client_credentials grant-type support.
  2. password grant-type support.
  3. Automatically refreshing tokens

The following features are planned mid/long-term

  1. Supply an OAuth2 discovery document instead of authorization and token uris.
  2. Supply a known access token and refresh token instead of going through the flow of obtaining these.
  3. authorization_code grant-type support
  4. implicit grant-type support
  5. Custom token storage (allowing people to store tokens in for example LocalStorage).

Keywords

FAQs

Package last updated on 12 Mar 2019

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