# @vpriem/express-api-key-auth

> Tiny express middleware to authenticate x-api-key request header

Latest version **1.3.0** (published 2023-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @vpriem/express-api-key-auth
pnpm add @vpriem/express-api-key-auth
yarn add @vpriem/express-api-key-auth
bun add @vpriem/express-api-key-auth
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2023-10-01 |
| First published | 2021-01-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18.x |
| Dependencies | 2 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | V. Priem |
| Maintainers | vpriem |
| Keywords | express, middleware, auth, x-api-key |

## Links

- npm: https://www.npmjs.com/package/@vpriem/express-api-key-auth
- Repository: https://github.com/vpriem/ts-monorepo
- Homepage: https://github.com/vpriem/ts-monorepo#readme
- Issues: https://github.com/vpriem/ts-monorepo/issues
- npm.io page: https://npm.io/package/@vpriem/express-api-key-auth

## Dependencies (2)

- [http-errors](https://npm.io/package/http-errors.md) 2.0.0
- [@types/express](https://npm.io/package/@types/express.md) 4.17.18

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.3.0 (latest) — 2023-10-01
- 1.2.0 — 2023-07-03
- 1.1.0 — 2022-12-26
- 1.0.7 — 2022-06-17
- 1.0.6 — 2022-01-31
- 1.0.5 — 2021-05-23
- 1.0.4 — 2021-03-02
- 1.0.3 — 2021-01-25
- 1.0.2 — 2021-01-22
- 1.0.1 — 2021-01-21
- 1.0.0 — 2021-01-19

## README

# express-api-key-auth

Tiny express middleware to authenticate `x-api-key` request header.

## Install

```shell
yarn add @vpriem/express-api-key-auth
```

## API

```typescript
import { apiKeyAuth } from '@vpriem/express-api-key-auth';
```

### apiKeyAuth(apiKeys: string[]): Handler

Create an express middleware with a given list of allowed api keys.  
Throwing `401` for all request with header `x-api-key` not matching the given list.

```typescript
import { apiKeyAuth } from '@vpriem/express-api-key-auth';

express().use(apiKeyAuth(['my-api-key1', 'my-api-key2']));
```

### apiKeyAuth(regExp: RegExp): Handler

Create the auth middleware based on all env vars with the name matching the given RegExp.

```typescript
import { apiKeyAuth } from '@vpriem/express-api-key-auth';

express().use(apiKeyAuth(/^API_KEY_/));
```

This will create a handler with a list of api keys matching all `process.env.API_KEY_*` env vars.

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/@vpriem/express-api-key-auth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
