Socket
Book a DemoInstallSign in
Socket

@evokegroup/oauth2

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@evokegroup/oauth2

Helper for OAuth2

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
4
Created
Source

@evokegroup/oauth2

Library for helping with OAuth 2.0 authorizations

Class: OAuth2

Class: OAuth2.AccessToken

constructor({ authResponse, value = null, expires = 0 })

ParameterTypeDefaultDescription
authResponseobject,stringThe authorization response
valuestringnullAn existing access token value
expiresnumber0The expiration date for an existing token

get value => string

Returns the access token value

get expires => number

Returns the expiration date

get created => number

Returns the date the AccessToken was created

get(parameter = null) => object | string

Get a parameter that was returned with the authorization response or all parameters if null

isExpired() => boolean

toJSON() => object

For JSON.stringify

toObject() => object

static parse(obj) => OAuth2.AccessToken

Parses an AccessToken

Class: OAuth2.Authorizer

Abstract base class for authorization implementations

abstract getAccessToken() => OAuth2.AccessToken

abstract setAccessToken(accessToken)

authorize() => Promise<OAuth2.AccessToken>

Determines if a valid AccessToken exists via getAccessToken and is valid via AccessToken.isExpired and if so resolved the Promise passing in the token. Otherwise authenticate is called.

abstract authenticate() => Promise<OAuth2.AccessToken>

Class: OAuth2.WebTokenAuthorizer extends OAuth2.Authorizer

An OAuth2.Authorizer implementation which makes a web request to retrive the token

constructor(args)

ParameterTypeDefaultDescription
urlstringThe authentication server URL
clientIdstringnullThe client_id parameter
clientSecretstringnullThe client_secret parameter
scopestringnullThe scope parameter
grantTypestringclient_credentialsThe grant_type parameter. If for some reason this should not be part of the payload, set it to null.
parametersobject{}Additional payload parameters. Overrides other data.
contentTypestringapplication/jsonThe Content-Type request header.
headersobject{}Additional request headers. Override other data.
timeoutnumber30000The request timeout in milliseconds
cachebooleantrueIf true, the OAuth2.AccessToken created during authentication will be cached and reused while valid
const OAuth2 = require('@evokegroup/oauth2');
const webTokenAuthorizer = new OAuth2.WebTokenAuthorizer({
  url: 'https://api.domain.com/auth/token',
  clientId: 'abc',
  clientSecret: '123'
});
webTokenAuthorizer.authorize()
  .then((accessToken) => {
    // do something with the access token
  })

FAQs

Package last updated on 06 Jun 2023

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