Socket
Book a DemoInstallSign in
Socket

cloudflare-workers-auth

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cloudflare-workers-auth

API key authentication for Cloudflare Workers

0.0.2
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

cloudflare-workers-auth

API key authentication for Cloudflare Workers

Install

$ npm install cloudflare-workers-auth cloudflare-workers

Usage

const worker = require('cloudflare-workers');
const auth = require('cloudflare-workers-auth');

auth.init({
    apiKeyHeader: 'x-apikey',
    apiKeys: [ 'key123', 'keyabc', 'keyxyz' ]
})

worker.get('/', (request) => new Response('welcome\n'));
worker.use('/protected*', auth.apiKey);
worker.get('/protected', (request) => new Response('path protected by apikey\n'));
worker.get('/protected/account', (request) => new Response('account info: apikey protected\n'));
worker.get('/protected/address', (request) => new Response('address details: apikey protected\n'));
worker.get('/public', (request) => new Response('public path: not apikey protected\n'));

addEventListener('fetch', function(event) {
    event.respondWith(worker.handleRequest(event));
});

See 'Using NPM modules' to require the package in your worker.

Design

This package is designed as middleware for the 'cloudflare-workers' routing package.

License

MIT license; see LICENSE.

FAQs

Package last updated on 04 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.