šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
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
npm
Version published
Weekly downloads
1
-80%
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