secondsky/claude-skills / plugins/cloudflare-zero-trust-access/skills/cloudflare-zero-trust-access
cloudflare-zero-trust-access
VerifiedCloudflare Zero Trust Access authentication for Workers. Use for JWT validation, service tokens, CORS, or encountering preflight blocking, cache race conditions, missing JWT headers.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 10.1 KB |
| references/access-policy-setup.md | markdown | 13.5 KB |
| references/common-errors.md | markdown | 15.1 KB |
| references/jwt-payload-structure.md | markdown | 12.8 KB |
| references/quick-start.md | markdown | 1.8 KB |
| references/service-tokens-guide.md | markdown | 15.3 KB |
| references/use-cases.md | markdown | 8.1 KB |
| references/value-proposition.md | markdown | 1.6 KB |
| scripts/create-service-token.shexecutable | script | 8.3 KB |
| scripts/test-access-jwt.shexecutable | script | 10.8 KB |
| templates/.env.example | other | 4.2 KB |
| templates/cors-access.ts | script | 8.1 KB |
| templates/hono-basic-setup.ts | script | 3.8 KB |
| templates/jwt-validation-manual.ts | script | 6.6 KB |
| templates/multi-tenant.ts | script | 10.1 KB |
| templates/service-token-auth.ts | script | 7.5 KB |
| templates/types.ts | script | 8.5 KB |
| templates/wrangler.jsonc | other | 3.9 KB |
templates/hono-basic-setup.ts
View on GitHub/**
* Cloudflare Zero Trust Access - Basic Hono Setup
*
* This template shows the recommended pattern for integrating Cloudflare Access
* with a Hono Worker application.
*
* Prerequisites:
* - Cloudflare Access application configured for your Worker domain
* - Access policy created with authentication rules
* - Environment variable ACCESS_TEAM_DOMAIN set (e.g., "your-team.cloudflareaccess.com")
*
* Install:
* npm install hono @hono/cloudflare-access
*/
import { Hono } from 'hono'
import { cloudflareAccess } from '@hono/cloudflare-access'
type Env = {
ACCESS_TEAM_DOMAIN: string
// Add other bindings as needed (D1, KV, R2, etc.)
}
const app = new Hono<{ Bindings: Env }>()
// ============================================================================
// PUBLIC ROUTES (No authentication required)
// ============================================================================
app.get('/', (c) => {
return c.html(`
<!DOCTYPE html>
<html>
<head><title>Public Page</title></head>
<body>
<h1>Welcome to the Public Page</h1>
<p>This page is accessible to everyone.</p>
<a href="/admin">Go to Admin Dashboard</a>
</body>
</html>
`)
})
app.get('/public-api', (c) => {
return c.json({
message: 'This is a public API endpoint',
authenticated: false,
})
})
// ============================================================================
// PROTECTED ROUTES (Access authentication required)
// ============================================================================
// Apply Access middleware to all /admin routes
app.use(
'/admin/*',
cloudflareAccess({
domain: (c) => c.env.ACCESS_TEAM_DOMAIN,
})
)
app.get('/admin', (c) => {
// Access payload is available in context after authentication
const accessPayload = c.get('accessPayload')
return c.html(`
<!DOCTYPE html>
<html>
<head><title>Admin Dashboard</title></head>
<body>
<h1>Admin Dashboard</h1>
<p>Welcome, ${accessPayload.email}!</p>
<h2>Your Details:</h2>
<ul>
<li>Email: ${accessPayload.email}</li>
<li>Groups: ${accessPayload.groups?.join(', ') || 'None'}</li>
<li>Country: ${accessPayload.country || 'Unknown'}</li>
</ul>
<a href="/">Back to Public Page</a>
</body>
</html>
`)
})
app.get('/admin/api/profile', (c) => {
const accessPayload = c.get('accessPayload')
return c.json({
email: accessPayload.email,
groups: accessPayload.groups || [],
country: accessPayload.country,
authenticated: true,
})
})
// ============================================================================
// PROTECTED API ROUTES (Alternative pattern - protect all /api routes)
// ============================================================================
// You can also protect API routes separately
// Uncomment this block if you want all API routes protected:
/*
app.use(
'/api/*',
cloudflareAccess({
domain: (c) => c.env.ACCESS_TEAM_DOMAIN,
})
)
app.get('/api/data', (c) => {
const accessPayload = c.get('accessPayload')
return c.json({
data: 'sensitive information',
user: accessPayload.email,
})
})
*/
// ============================================================================
// ERROR HANDLING
// ============================================================================
app.onError((err, c) => {
console.error('Error:', err)
// Handle Access-specific errors
if (err.message.includes('Access')) {
return c.json(
{
error: 'Authentication failed',
message: 'Please ensure you are accessing this page through Cloudflare Access',
},
401
)
}
return c.json(
{
error: 'Internal server error',
message: err.message,
},
500
)
})
// ============================================================================
// 404 NOT FOUND
// ============================================================================
app.notFound((c) => {
return c.json({ error: 'Not found' }, 404)
})
export default app
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |