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

@endpass/endpass-node

Package Overview
Dependencies
Maintainers
6
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@endpass/endpass-node

Endpass Connect client for node.js backend

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
6
Weekly downloads
 
Created
Source

Endpass OAuth2 client

Installation

Install client with your favorite package manager. For example with yarn:

yarn add endpass-node

Or with npm:

npm i --save endpass-node

Usage

This library allows to use endpass public API. Before requesting you should create your owl application at Vault and create client.

For example, we want to create client for requesting user data:

const { Client } = require('endpass-node');

const client = new Client({
  clientId: '<your_application_id>',
  clientSecret: '<your_application_secret>',
  scopes: ['user:email:read', 'user:phone:read'],
  state: '<random_string>',
  redirectUrl: '<your_application_redirect_url>',
});

You can generate authorization code with getAuthUrl method and redirect user for receive authorization code, which can be used for access token requesting.

When you will receive authorization code you can try to request access token and make some requests with that:

const token = await client.exchange('<authorization_code>');

try {
  const { email } = await client.request({
    path: '/user',
    accessToken: token.accessToken,
  });

  // There would be profile data
} catch (err) {
  // Error handling
}

Also, you can create EndpassRequester instance for multiple requests with one access token:

const token = await client.exchange('<authorization_code>');
const requester = client.createRequester(token.accessToken);

try {
  const { email } = await requester.request('/user');
  // ...
  // There would be profile data
} catch (err) {
  // Error handling
}

In the case abow, your access token will be cached in requester instance. Do not forget about access token expiration!

Notice: endpass-node client is not storing access tokens, you should solve it by yourself.

Also, yor can check example application here.

API reference

Client constructor

Notice: all properties are required.

PropertyDescription
clientIdOauth2 application client id
clientSecretOauth2 application client secret
scopesScopes which can be allowed to client requests
redirectUrlRedirect for receiving authorization code
stateUnique string for validating OAuth2 responses

Client methods

Notice: you can find more information in the JSDOC notations for each method.

MethodArgumentsReturned valueDescription
getAuthUrlstringReturns url where user can receive authorization code for token requesting
exchangecode: stringPromise<Token>Requests authorization token with authorization code
refreshrefreshToken: stringPromise<Token>Refresh authorization token with earlier received refresh token
request{ origin?: string, path: string, accessToken: string }Promise<object>Request some data from endpass public API endpoint with access token

FAQs

Package last updated on 14 Aug 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