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

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

## oauth-helper-temp
The following environment variables are used:

| Env variable name | Description | Default | Comments |
| ----------------- | ----------- | ------- | -------- |
| OAUTH_HELPER_TEMP_SOURCE | swagger source: `swaggerhub` or `bitbucket` | swaggerhub | |
| OAUTH_HELPER_TEMP_ACCOUNT | swagger account to use for accessing API on swaggerhub | mimik | swaggerhub only |
| OAUTH_HELPER_TEMP_API_KEY | API key for the private API on swaggerhub | | swaggerhub only |
| OAUTH_HELPER_TEMP_BITBUCKET_KEY_PATH | path to key.json with bitbucket credentials | | bitbucket only |
| OAUTH_HELPER_TEMP_BITBUCKET_WORKSPACE | bitbucket workspace | mimiktech | bitbucket only |
| OAUTH_HELPER_TEMP_BITBUCKET_API_URL | bitbucket API base URL | https://api.bitbucket.org/2.0/repositories | bitbucket only |

The config should contain the customerCode if needed. If the customerCode is not available in the config, a default uuid will be used.

When `OAUTH_HELPER_TEMP_SOURCE` is set to `bitbucket`, swagger definitions are fetched from Bitbucket repositories
instead of SwaggerHub. The key.json file must contain `{ "bitbucket": { "username": "...", "password": "..." } }`.
The latest version is determined from the repository's semver tags.

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

* [oauth-helper-temp](#module_oauth-helper-temp)
    * _static_
        * [.getAdminTokens(mSTAdminToken, mSTBaseUrl, customerName, environment, targets, correlationId)](#module_oauth-helper-temp.getAdminTokens) ⇒ <code>Promise</code>
        * [.getSystemTokens(mSTAdminToken, mSTBaseUrl, customerName, typePairs, correlationId)](#module_oauth-helper-temp.getSystemTokens) ⇒ <code>Promise</code>
    * _inner_
        * [~rpAuth(type, options)](#module_oauth-helper-temp..rpAuth) ⇒ <code>Promise</code>
        * [~createUserToken(type, userId, appId, correlationId)](#module_oauth-helper-temp..createUserToken) ⇒ <code>Promise</code>
        * [~createUserTokenAll(types, userId, appId, correlationId)](#module_oauth-helper-temp..createUserTokenAll) ⇒ <code>Promise</code>
        * [~createUserTokenWithOnBehalf(type, userId, appId, onBehalfId, correlationId)](#module_oauth-helper-temp..createUserTokenWithOnBehalf) ⇒ <code>Promise</code>
        * [~createUserTokenAllWithOnBehalf(types, userId, appId, onBehalfId, correlationId)](#module_oauth-helper-temp..createUserTokenAllWithOnBehalf) ⇒ <code>Promise</code>
        * [~createAdminToken(type, customerCode, correlationId)](#module_oauth-helper-temp..createAdminToken) ⇒ <code>Promise</code>
        * [~createSystemToken(type, customerCode, correlationId)](#module_oauth-helper-temp..createSystemToken) ⇒ <code>Promise</code>

<a name="module_oauth-helper-temp.getAdminTokens"></a>

### oauth-helper-temp.getAdminTokens(mSTAdminToken, mSTBaseUrl, customerName, environment, targets, correlationId) ⇒ <code>Promise</code>
Get admin tokens.

**Kind**: static method of [<code>oauth-helper-temp</code>](#module_oauth-helper-temp)  
**Returns**: <code>Promise</code> - .  
**Category**: async  
**Fulfil**: <code>object</code> An array of responses with tokens.

config is ignored for that function.  

| Param | Type | Description |
| --- | --- | --- |
| mSTAdminToken | <code>string</code> | Token to access admin operation of mST. |
| mSTBaseUrl | <code>URL.&lt;string&gt;</code> | BaseUrl to use to access mST endpoints. |
| customerName | <code>string</code> | Name of the customer for which the token will be provided. |
| environment | <code>string</code> | Environment used to define the admin tokens. |
| targets | <code>array</code> | Array of { type } to get the admin tokens. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId associated with the creation of the tokens. |

<a name="module_oauth-helper-temp.getSystemTokens"></a>

### oauth-helper-temp.getSystemTokens(mSTAdminToken, mSTBaseUrl, customerName, typePairs, correlationId) ⇒ <code>Promise</code>
Get system tokens.

**Kind**: static method of [<code>oauth-helper-temp</code>](#module_oauth-helper-temp)  
**Returns**: <code>Promise</code> - .  
**Category**: async  
**Fulfil**: <code>object</code> An array of responses with tokens.

config is ignored for that function.  

| Param | Type | Description |
| --- | --- | --- |
| mSTAdminToken | <code>string</code> | Token to access admin operation of mST. |
| mSTBaseUrl | <code>URL.&lt;string&gt;</code> | BaseUrl to use to access mST endpoints. |
| customerName | <code>string</code> | Name of the customer for which the token will be provided. |
| typePairs | <code>object</code> | Array of pair of { origType, destType } to get the system tokens. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId associated with the creation of the tokens. |

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

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

**Kind**: inner method of [<code>oauth-helper-temp</code>](#module_oauth-helper-temp)  
**Returns**: <code>Promise</code> - .  
**Category**: async  
**Throws**:

- <code>Promise</code> Will throw the same error as rpauth in oauth-helper.

**Fulfil**: <code>object</code> - Response from the authorized request.  

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type of micro service to request. |
| options | <code>object</code> | Options for the request. Similar to rpauth in `oauth-helper` options. |

<a name="module_oauth-helper-temp..createUserToken"></a>

### oauth-helper-temp~createUserToken(type, userId, appId, correlationId) ⇒ <code>Promise</code>
Create a user token.

**Kind**: inner method of [<code>oauth-helper-temp</code>](#module_oauth-helper-temp)  
**Returns**: <code>Promise</code> - .  
**Category**: async  
**Throws**:

- <code>Promise</code> Will throw the same error if the token cannot be created.

**Fulfil**: <code>JWT&lt;object&gt;</code> The user token.  

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type of micro-service to request. |
| userId | <code>string</code> | User id to assign to the token. |
| appId | <code>string</code> | Application id to associate with the request. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId associated with the creation of the token. |

<a name="module_oauth-helper-temp..createUserTokenAll"></a>

### oauth-helper-temp~createUserTokenAll(types, userId, appId, correlationId) ⇒ <code>Promise</code>
Create a user token with many services.

**Kind**: inner method of [<code>oauth-helper-temp</code>](#module_oauth-helper-temp)  
**Returns**: <code>Promise</code> - .  
**Category**: async  
**Throws**:

- <code>Promise</code> Will throw the same error if the token cannot be created.

**Fulfil**: <code>JWT&lt;object&gt;</code> The user token.  

| Param | Type | Description |
| --- | --- | --- |
| types | <code>Array.&lt;string&gt;</code> | Array of type of micro-service to request. |
| userId | <code>string</code> | User id to assign to the token. |
| appId | <code>string</code> | Application id to associate with the request. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId associated with the creation of the token. |

<a name="module_oauth-helper-temp..createUserTokenWithOnBehalf"></a>

### oauth-helper-temp~createUserTokenWithOnBehalf(type, userId, appId, onBehalfId, correlationId) ⇒ <code>Promise</code>
Create an onBehalfId token.

**Kind**: inner method of [<code>oauth-helper-temp</code>](#module_oauth-helper-temp)  
**Returns**: <code>Promise</code> - .  
**Category**: async  
**Throws**:

- <code>Promise</code> Will throw the same error if the token cannot be created.

**Fulfil**: <code>JWT&lt;object&gt;</code> The onBehalf token.  

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type of micro-service to request. |
| userId | <code>string</code> | User id to assign to the token. |
| appId | <code>string</code> | Application id to associate with the request. |
| onBehalfId | <code>string</code> | User id to assign to the token to act on behalf. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId associated with the creation of the token. |

<a name="module_oauth-helper-temp..createUserTokenAllWithOnBehalf"></a>

### oauth-helper-temp~createUserTokenAllWithOnBehalf(types, userId, appId, onBehalfId, correlationId) ⇒ <code>Promise</code>
Create an onBehalfId token with many services.

**Kind**: inner method of [<code>oauth-helper-temp</code>](#module_oauth-helper-temp)  
**Returns**: <code>Promise</code> - .  
**Category**: async  
**Throws**:

- <code>Promise</code> Will throw the same error if the token cannot be created.

**Fulfil**: <code>JWT&lt;object&gt;</code> The onBehalf token.  

| Param | Type | Description |
| --- | --- | --- |
| types | <code>Array.&lt;string&gt;</code> | Array of type of micro-service to request. |
| userId | <code>string</code> | User id to assign to the token. |
| appId | <code>string</code> | Application id to associate with the request. |
| onBehalfId | <code>string</code> | User id to assign to the token to act on behalf. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId associated with the creation of the token. |

<a name="module_oauth-helper-temp..createAdminToken"></a>

### oauth-helper-temp~createAdminToken(type, customerCode, correlationId) ⇒ <code>Promise</code>
Create an admin token.

**Kind**: inner method of [<code>oauth-helper-temp</code>](#module_oauth-helper-temp)  
**Returns**: <code>Promise</code> - .  
**Category**: async  
**Throws**:

- <code>Promise</code> Will throw the same error if the token cannot be created.

**Fulfil**: <code>JWT&lt;object&gt;</code> The admin token.  

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type of micro-service to request. |
| customerCode | <code>UUID.&lt;string&gt;</code> | customer code to be added in the token. If not present, config.serverSettings.customerCode or randomUUID() will be used. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId associated with the creation of the token. |

<a name="module_oauth-helper-temp..createSystemToken"></a>

### oauth-helper-temp~createSystemToken(type, customerCode, correlationId) ⇒ <code>Promise</code>
Create a system token.

**Kind**: inner method of [<code>oauth-helper-temp</code>](#module_oauth-helper-temp)  
**Returns**: <code>Promise</code> - .  
**Category**: async  
**Throws**:

- <code>Promise</code> Will throw the same error if the token cannot be created.

**Fulfil**: <code>JWT&lt;object&gt;</code> The system token.  

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type of micro-service to request. |
| customerCode | <code>UUID.&lt;string&gt;</code> | customer code to be added in the token. If not present, config.serverSettings.customerCode or randomUUID() will be used. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId associated with the creation of the token. |