npm.io
1.3.0 • Published 2 years ago

@vpriem/express-api-key-auth

Licence
MIT
Version
1.3.0
Deps
2
Size
6 kB
Vulns
0
Weekly
0
Stars
7

express-api-key-auth

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

Install

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

API

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.

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.

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

Keywords