@vpriem/express-api-key-auth
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

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

Package Sidebar

Install

npm i @vpriem/express-api-key-auth

Weekly Downloads

783

Version

1.3.0

License

MIT

Unpacked Size

6.05 kB

Total Files

11

Last publish

Collaborators

  • vpriem