# @mimik/oauth-helper

> Oauth helper for mimik microservices

Latest version **4.3.1** (published 2026-07-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mimik/oauth-helper
pnpm add @mimik/oauth-helper
yarn add @mimik/oauth-helper
bun add @mimik/oauth-helper
```

## Health

**Score 50/100 (C)** — status: active.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 4.3.1 |
| Published | 2026-07-08 |
| First published | 2018-06-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=24.0.0 |
| Dependencies | 4 |
| Unpacked size | 17.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | mimik technology inc |
| Maintainers | mimik-npm-editor, hofachiang, miburger, mimikopensource, sasan.raisdana |
| Keywords | mimik, microservice |

## Links

- npm: https://www.npmjs.com/package/@mimik/oauth-helper
- Repository: https://bitbucket.org/mimiktech/oauth-helper
- Homepage: https://bitbucket.org/mimiktech/oauth-helper#readme
- Issues: https://bitbucket.org/mimiktech/oauth-helper/issues
- npm.io page: https://npm.io/package/@mimik/oauth-helper

## Dependencies (4)

- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) 9.0.3
- [@mimik/request-retry](https://npm.io/package/@mimik/request-retry.md) ^4.1.1
- [@mimik/response-helper](https://npm.io/package/@mimik/response-helper.md) ^4.1.1
- [@mimik/sumologic-winston-logger](https://npm.io/package/@mimik/sumologic-winston-logger.md) ^2.3.1

## Recent versions

- 4.3.1 (latest) — 2026-07-08
- 4.1.3 — 2026-03-22
- 4.1.2 — 2026-03-17
- 4.1.1 — 2026-03-13
- 4.1.0 — 2026-03-02
- 4.0.2 — 2025-07-22
- 4.0.1 — 2025-04-17
- 4.0.0 — 2025-04-17
- 3.0.2 — 2024-07-24
- 3.0.1 — 2023-12-05
- 3.0.0 — 2023-04-23
- 2.2.0 — 2023-04-11
- 2.1.0 — 2023-03-05
- 2.0.2 — 2022-12-26
- 2.0.1 — 2022-12-25
- … 17 more at https://npm.io/package/@mimik/oauth-helper/versions

## README

<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. When `authProfile` is used, `config.dependencies.mID.url` (base URL of the identity server) is also required. |

<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 rich error from [@mimik/request-retry](https://www.npmjs.com/package/@mimik/request-retry).

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

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type of microservice to request. |
| options | <code>object</code> | Options for the request. Similar to [@mimik/request-retry](https://www.npmjs.com/package/@mimik/request-retry) (axios-style) 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 defined.

**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. |

---
_Source: https://npm.io/package/@mimik/oauth-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
