npm.io
4.3.1 • Published 3 months ago

@mimik/oauth-helper

Licence
MIT
Version
4.3.1
Deps
4
Size
18 kB
Vulns
0
Weekly
0

oauth-helper

Example

import oauthHelper from '@mimik/oauth-helper';

oauth-helper~oauthHelper(config) ⇒ object

Create an OAuth helper instance for making authorized requests.

Kind: inner method of oauth-helper
Returns: object - Object with rpAuth and authProfile methods.

Param Type Description
config object Service configuration.
config.security object Security settings.
config.security.server object Token server configuration.
config.security.server.issuer string Token issuer URL.
config.security.server.id string Client ID.
config.security.server.secret string Client secret.
config.dependencies object Dependency type to settings map. Each entry must have an audience string. When authProfile is used, config.dependencies.mID.url (base URL of the identity server) is also required.

oauth-helper~rpAuth(type, options) ⇒ Promise

Make an authorized request.

Kind: inner method of oauth-helper
Returns: Promise - Resolves with the response from the authorized request.
Category: async
Throws:

The property token may be added to options, in order to set up how the token is retrieved from the token manager. The structure is:

{
   "retry": "object to specify how the retry to the token manager will be done. similar to rp-retry retry property",
   "customerName": "name of the customer for which the token is intended, see mST API",
   "cluster": "to set the token to be a cluster token"
}

The property metrics may be added to options, in order to set up metrics about calls made to other microservices. The structure is:

{
    "HTTPRequestDuration": "prom-client function to label and record the elapsed time",
    "url": "url to be displayed for the metrics. If not present the url of the options will be used"
}

Requires: module:@mimik/sumologic-winston-logger
Fulfil: object - Response of the @mimik/request-retry request.

Param Type Description
type string Type of microservice to request.
options object Options for the request. Similar to @mimik/request-retry (axios-style) options.

oauth-helper~authProfile(method, id, correlationId, [options]) ⇒ Promise

Make an authProfile request to mID.

Kind: inner method of oauth-helper
Returns: Promise - Resolves with the response from mID.
Category: async
Throws:

  • Error Will throw a rich error if the request fails or an error if the id is not defined.

Requires: module:@mimik/sumologic-winston-logger
Fulfil: object The response of the request made to mID.

Param Type Description
method string Method (GET, DELETE) of the request to be made.
id string UserId associated with the request.
correlationId string CorrelationId associated with the request.
[options] object Options to be added to the request. metrics can then be added to the options.

Keywords