Skip to content

workers-auth

Drop-in authentication and authorization for Cloudflare Workers. Magic links, GitHub OAuth, RBAC, sessions — all running on the edge.

workers-auth gives you a complete auth system for Cloudflare Workers with zero external services beyond what you already have on Cloudflare.

  • Authentication strategies — Magic link emails and GitHub OAuth, with a pluggable interface for custom strategies
  • Authorization — Role-based access control (RBAC) with wildcard permissions
  • Edge-native storage — D1 for users/sessions, KV for fast session caching
  • Hono middlewareauthenticate and authorize middleware that plug directly into your Hono app
  • Pluggable architecture — Swap adapters, providers, and strategies without changing your app code
Terminal window
npm install workers-auth hono
import { WorkersAuth } from 'workers-auth';
import { MagicLinkStrategy } from 'workers-auth/authn/magic-link';
import { D1Adapter } from 'workers-auth/adapters/d1';
import { KVAdapter } from 'workers-auth/adapters/kv';
const auth = WorkersAuth({
database: (binding) => D1Adapter(binding),
cache: (binding) => KVAdapter(binding),
authn: { strategies: [MagicLinkStrategy({ provider, template })] },
redirectUrl: '/dashboard',
});
app.route('/auth', auth.handler);
app.use('/api/*', auth.authenticate);

Ready to set up? Head to the Quick Start guide.