# @openintegrationhub/iam-utils

> Utils and express middleware for OIH IAM service

Latest version **1.7.3** (published 2022-09-26) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @openintegrationhub/iam-utils
pnpm add @openintegrationhub/iam-utils
yarn add @openintegrationhub/iam-utils
bun add @openintegrationhub/iam-utils
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.7.3 |
| Published | 2022-09-26 |
| First published | 2018-11-05 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 5 |
| Unpacked size | 33 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Basaas GmbH |
| Maintainers | drobiazko, cloudecosystem, basaas-dev, pnedelko, shoeffler, jkopen |

## Links

- npm: https://www.npmjs.com/package/@openintegrationhub/iam-utils
- npm.io page: https://npm.io/package/@openintegrationhub/iam-utils

## Dependencies (5)

- [request](https://npm.io/package/request.md) 2.88.0
- [base64url](https://npm.io/package/base64url.md) 3.0.1
- [node-cache](https://npm.io/package/node-cache.md) 4.2.0
- [request-promise](https://npm.io/package/request-promise.md) 4.2.4
- [@basaas/node-logger](https://npm.io/package/@basaas/node-logger.md) 1.1.5

## Recent versions

- 1.7.3 (latest) — 2022-09-26
- 1.7.2 — 2021-11-23
- 1.7.1 — 2021-11-03
- 1.7.0 — 2021-10-06
- 1.6.5 — 2021-08-27
- 1.6.4 — 2021-08-13
- 1.6.3 — 2021-06-02
- 1.6.2 — 2021-02-09
- 1.6.1 — 2020-12-18
- 1.6.0 — 2020-08-13
- 1.5.3 — 2019-10-29
- 1.5.2 — 2019-10-02
- 1.5.1 — 2019-09-02
- 1.5.0 — 2019-09-02
- 1.4.1 — 2019-08-01
- … 16 more at https://npm.io/package/@openintegrationhub/iam-utils/versions

## README

# iam-utils
Utils and middleware for OIH IAM service

This library provides an express middleware to validate the tokens issued by [OIH IAM](https://github.com/openintegrationhub/openintegrationhub/tree/master/services/iam) service (Heimdal).

## Env variables

`process.env`
* `IAM_TOKEN`: Service-Account token which is authorized to introspect other tokens
* `INTROSPECT_TYPE`: `basic` or `oidc`. Default: basic
* `INTROSPECT_ENDPOINT_BASIC`: IAM endpoint for basic token introspection
* `INTROSPECT_ENDPOINT_OIDC`: IAM endpoint for OIDC token introspection
* `OIDC_CLIENT_ID`: Your client id for OIDC
* `OIDC_CLIENT_SECRET_`: Your client secret for OIDC


## Usage

You can either use the util method `getUserData` or the express `middleware`.

### `async getUserData({ token, introspectType? })`

*Returns* Promise

This method accepts a token and returns a promise, which either resolves with the decoded object or is rejected with an error.
It introspects the token with a given `introspectType` (or with default, if not set).


### `middleware(req, res, next)`

You can plug this express middleware into your application logic/router. It will check for an `authorization` header containing the `Bearer` token and call the `getUserData` method internally.
The successfully decoded payload will be saved in `req.user` object, e.g.:

```
{
  "sub": "5b16927286b7f569feb1fae4",
  "username": "admin@example.com",
  "role": "USER",
  "memberships": [],
  "permissions": []
}
```


### FAQ

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