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

authenticated-api

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

authenticated-api

Send API with auto renew access token logic

  • 1.3.9
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Authenticated API

Send API with auto renew access token logic

Notice: using same Babel config as create-react-app.

Usage

yarn install authenticated-api

Create TokenProvider:

const tokenProvider = new TokenProvider();

Create API:

const api = new Api({
  tokenProvider,
  prefix: process.env.REACT_APP_API_ENDPOINT,
});

(Somewhere in your app) after get access token and refresh token:

tokenProvider.setToken({ accessToken, refreshToken });

Now you can call authenticated request with API object:

const response = api.get('https://somewhere.com/api/something');

Options

Api

const api = new Api(options);

options have following keys:

  • tokenProvider: token provider.
  • prefix: host name
  • fetcher: the method to call for request, default is global window.fetch;
  • logging: true/false whether print debug log or not

TokenProvider

API object will expect TokenProvider to have the following methods:

  • getAccessToken(): return access token
  • renewToken() (async): renew the access token

FAQs

Package last updated on 10 Jul 2018

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