2.0.9 • Published 5 years ago

oauth-api-client v2.0.9

Weekly downloads
21
License
MIT
Repository
github
Last release
5 years ago

node-api-client

NPM

Build StatuscodecovKnown Vulnerabilities

Version > 2.x is es6 compliant and uses promises

Usage

This module handles OAuth2 flow using credentials (username / password), authorization code and regular tokens (access_token, refresh_token) couple

Client

Creating a client is straightforward, the constructor takes two arguments

const config = {
    // Put configuration here ...
}
/**
 * Create OAuth2 client
 * @param baseUrl (string)
 * @param config (object)
 */
const client = new Client('https://api.test.com', config)

Options

Supported options

user_agent (string)

client_id (string)

client_secret (string)

urls (object)

Optional parameter

{
    api: 'https://api.test.com/',
    token: 'https://test.com/oauth2/token',
    authorize: 'https://test.com/oauth2/authorize'
}

Default value is:

{
    api: '{baseUrl}/',
    token: '{baseUrl}/token',
    authorize: '{baseUrl}/authorize'
}

where baseUrl is the first argument used in the constructor

timeout (integer)

Default value is 10s

access_token (string)

refresh_token (string)

expires_in (integer)

authorization_code (sring)

scope (string)

redirect_uri (string)

username (string)

password (string)

shouldRefreshToken (function)

Access token expiration is handled by the library, specific cases can be added by overriding this function.

Client.getAccessToken

Calling getAccessToken will return valid tokens.

Works with authorization code, username / password flow and a refresh_token when the access_token is expired.

client.getAccessToken()

Output example:

{
    "access_token": ... (string),
    "refresh_token": ... (string),
    "expires_in": ... (integer)
}

Client.get

client.get('v1/user', { ... })

Client.post

client.post('v1/user', { ... })

Errors

Error classes are exposed in require('oauth-api-client/errors')

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

1.0.1

5 years ago