Skip to content

Oauth

Reference for the MESA Oauth.js custom code class, covering refresh_token, password and custom grants and methods for authenticated API requests.

vendor/Oauth.js

Class containing methods to authenticate and make authenticated requests with a third party API

Name Type Description
grantType string Oauth grant type. One of: refresh_token, password, or custom.  
tokenKey string The key of the secret containing the oAuth token information.  
// Refresh token flow.
const Oauth = require('vendor/Oauth.js');
const oauth = new Oauth('refresh_token', 'service.oauth');
// Username password flow.
const Oauth = require('vendor/Oauth.js');
// Save username and password from external standalone secrets.
let token = JSON.decode(Mesa.secret.get('service.oauth', '{}'));
token.username = Mesa.secret.get('service-username');
token.password = Mesa.secret.get('service-password');
Mesa.secret.set('service.oauth', JSON.stringify(token));
const oauth = new Oauth('password', 'service.oauth');
// Skubana flow (access_token that does not expire)
const Oauth = require('vendor/Oauth.js');
const oauth = new Oauth('custom', 'skubana.oauth');
const getResponse = oauth.get('https://dev.skubana.com/v1/orders');
Mesa.log.info('Get Response: ', getResponse);
// Oauth Usage
const getResponse = oauth.get('https://example.com/products.json');
const postResponse = oauth.post('https://example.com/products.json', {});
Mesa.log.info('Get Response: ', getResponse);
Mesa.log.info('Post Response: ', postResponse);
  • Void

constructor(grantType, tokenKey, hasHeaders)

Section titled “constructor(grantType, tokenKey, hasHeaders)”
Name Type Description
grantType string  
tokenKey string  
hasHeaders boolean  
  • Void

Init the access token

  • Void

Request method with the refresh token retry if fails.

Name Type Description
method string Request method.  
path string Request path.  
data object  
options Types.RequestOptions Additional configuration for Oauth calls  
  • object

Make a GET request to an external Rest API

Name Type Description
path string Request path  
options Types.RequestOptions Additional configuration for Oauth calls Optional
  • object

Make a POST request to an external Rest API.

Name Type Description
path string Request path  
data object Request payload  
options Types.RequestOptions Additional configuration for Oauth calls Optional
  • object

Make a PUT request to an external Rest API.

Name Type Description
path string Request path  
data object Request payload  
options Types.RequestOptions Additional configuration for Oauth calls Optional
  • object

Make a PATCH request to an external Rest API.

Name Type Description
path string Request path  
data object Request payload  
options Types.RequestOptions Additional configuration for Oauth calls Optional
  • object

Make a DELETE request to an external Rest API.

Name Type Description
path string Request path  
options Types.RequestOptions Additional configuration for Oauth calls Optional
  • object