Socket
Socket
Sign inDemoInstall

authenticated-api

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    authenticated-api

Send API with auto renew access token logic


Version published
Maintainers
1
Install size
162 kB
Created

Readme

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

Last updated on 10 Jul 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc