npm package: @mimik/oauth-helper
Description: Oauth helper for mimik microservices
Author: mimik technology inc
Latest version: 4.1.3

<a name="module_oauth-helper"></a>

## oauth-helper
**Example**  
```js
import oauthHelper from '@mimik/oauth-helper';
```

* [oauth-helper](#module_oauth-helper)
    * [~oauthHelper(config)](#module_oauth-helper..oauthHelper) ⇒ <code>object</code>
    * _async_
        * [~rpAuth(type, options)](#module_oauth-helper..rpAuth) ⇒ <code>Promise</code>
        * [~authProfile(method, id, correlationId, [options])](#module_oauth-helper..authProfile) ⇒ <code>Promise</code>

<a name="module_oauth-helper..oauthHelper"></a>

### oauth-helper~oauthHelper(config) ⇒ <code>object</code>
Create an OAuth helper instance for making authorized requests.

**Kind**: inner method of [<code>oauth-helper</code>](#module_oauth-helper)  
**Returns**: <code>object</code> - Object with `rpAuth` and `authProfile` methods.  

| Param | Type | Description |
| --- | --- | --- |
| config | <code>object</code> | Service configuration. |
| config.security | <code>object</code> | Security settings. |
| config.security.server | <code>object</code> | Token server configuration. |
| config.security.server.issuer | <code>string</code> | Token issuer URL. |
| config.security.server.id | <code>string</code> | Client ID. |
| config.security.server.secret | <code>string</code> | Client secret. |
| config.dependencies | <code>object</code> | Dependency type to settings map. Each entry must have an `audience` string. |

<a name="module_oauth-helper..rpAuth"></a>

### oauth-helper~rpAuth(type, options) ⇒ <code>Promise</code>
Make an authorized request.

**Kind**: inner method of [<code>oauth-helper</code>](#module_oauth-helper)  
**Returns**: <code>Promise</code> - Resolves with the response from the authorized request.  
**Category**: async  
**Throws**:

- <code>Error</code> Will throw the same error as [request-promise](https://www.npmjs.com/package/request-promise).

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 microservice. 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**: <code>module:@mimik/sumologic-winston-logger</code>  
**Fulfil**: <code>object</code> - Response of the [request-promise](https://www.npmjs.com/package/request-promise) request.  

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type of micro service to request. |
| options | <code>object</code> | Options for the request. Similar to [request-promise](https://www.npmjs.com/package/request-promise) options. |

<a name="module_oauth-helper..authProfile"></a>

### oauth-helper~authProfile(method, id, correlationId, [options]) ⇒ <code>Promise</code>
Make an authProfile request to mID.

**Kind**: inner method of [<code>oauth-helper</code>](#module_oauth-helper)  
**Returns**: <code>Promise</code> - Resolves with the response from mID.  
**Category**: async  
**Throws**:

- <code>Error</code> Will throw a rich error if the request fails or an error if the id is not identified.

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

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