Socket
Socket
Sign inDemoInstall

cloudflare-workers-auth

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cloudflare-workers-auth

API key authentication for Cloudflare Workers


Version published
Weekly downloads
1
Maintainers
1
Install size
3.46 kB
Created
Weekly downloads
 

Readme

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

Last updated on 04 May 2019

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc