{"_id":"@autolabz/service-auth-hono","_rev":"2-73d11e2560d3e3557683c068229126cd","name":"@autolabz/service-auth-hono","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.2":{"name":"@autolabz/service-auth-hono","version":"1.0.2","_id":"@autolabz/service-auth-hono@1.0.2","maintainers":[{"name":"autolabz","email":"mzhh@mzhh.xyz"}],"dist":{"shasum":"66a5a02e10b971a25d545e78442873db181fb2fb","tarball":"https://registry.npmjs.org/@autolabz/service-auth-hono/-/service-auth-hono-1.0.2.tgz","fileCount":8,"integrity":"sha512-SoKw8/1xFq0kriOVBVUCf1FCut9+znY/Fljnhd3K/rYuLQQTYfVcI969a+k3SnQduWrfmk02Xdi7r5NYhygExA==","signatures":[{"sig":"MEUCIBplOHKrebkwbzlFCtYXvU6gTSeagiy1s9yRG6mtPH4kAiEA6kF97Lw9TO+fn7dd+pczhruWs9OXeaE1n8C7YJda7Jc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":59727},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"f1597a752ed7afb3db7156f0eb56f3c72f191283","scripts":{"build":"npm run clean && tsup src/index.ts --format esm,cjs --dts --sourcemap --clean --target es2020","clean":"rimraf dist","prepare":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit"},"_npmUser":{"name":"autolabz","email":"mzhh@mzhh.xyz"},"_npmVersion":"10.8.2","description":"Hono / Cloudflare Workers authentication middleware for AutoLab services","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","dependencies":{"@autolabz/service-auth-core":"^1.0.1"},"_hasShrinkwrap":false,"devDependencies":{"hono":"^4.0.0","tsup":"^8.3.0","rimraf":"^5.0.5","typescript":"^5.6.3"},"peerDependencies":{"hono":"^4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/service-auth-hono_1.0.2_1771389324934_0.45323096818615727","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@autolabz/service-auth-hono","version":"1.0.3","type":"module","description":"Hono / Cloudflare Workers authentication middleware for AutoLab services","sideEffects":false,"main":"dist/index.cjs","module":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"peerDependencies":{"hono":"^4.0.0"},"dependencies":{"@autolabz/service-auth-core":"^1.0.7"},"devDependencies":{"hono":"^4.0.0","rimraf":"^5.0.5","tsup":"^8.3.0","typescript":"^5.6.3"},"scripts":{"clean":"rimraf dist","build":"npm run clean && tsup src/index.ts --format esm,cjs --dts --sourcemap --clean --target es2020","prepare":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit"},"_id":"@autolabz/service-auth-hono@1.0.3","gitHead":"f1597a752ed7afb3db7156f0eb56f3c72f191283","_nodeVersion":"20.19.5","_npmVersion":"10.8.2","dist":{"integrity":"sha512-Afby/AiIdGb+DD/+mfhaew81GtyAnnn0OZ8LGHftqXrCnOWuSOzVfSNNemcNYPycfCT2ijUHLAVUZnVjCkLJRw==","shasum":"7fab312a440c7cdc025a5a52f15054129c0e732e","tarball":"https://registry.npmjs.org/@autolabz/service-auth-hono/-/service-auth-hono-1.0.3.tgz","fileCount":8,"unpackedSize":59727,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDe/Y+W69Y8q7bKc4VxIsOUKMOOSTY536BSM+fOX1FbAQIgGq6mE9VWISqQZNcaW4GNEz4RLyGkla5xbljS7P/TVKQ="}]},"_npmUser":{"name":"autolabz","email":"mzhh@mzhh.xyz"},"directories":{},"maintainers":[{"name":"autolabz","email":"mzhh@mzhh.xyz"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/service-auth-hono_1.0.3_1771485741236_0.4982673261825237"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-18T04:35:24.826Z","modified":"2026-02-19T07:22:21.473Z","1.0.2":"2026-02-18T04:35:25.077Z","1.0.3":"2026-02-19T07:22:21.368Z"},"description":"Hono / Cloudflare Workers authentication middleware for AutoLab services","maintainers":[{"name":"autolabz","email":"mzhh@mzhh.xyz"}],"readme":"# @autolabz/service-auth-hono\n\nHono / Cloudflare Workers authentication middleware for AutoLab services: JWT verification with OAuth userinfo fallback, client_id and scope enforcement.\n\n## Features\n\n- **Unified auth chain**: JWT first (SIMPLE), then OAuth userinfo fallback\n- **OAuth validation**: X-Client-Id vs azp, optional required scopes\n- **Framework-agnostic core**: Built on `@autolabz/service-auth-core`\n- **Worker-ready**: No Node-only APIs; works on Cloudflare Workers\n\n## Installation\n\n```bash\nnpm install @autolabz/service-auth-hono hono\n```\n\n## Quick Start\n\n### One-shot middleware chain\n\n```typescript\nimport { Hono } from 'hono';\nimport { authMiddlewareChain } from '@autolabz/service-auth-hono';\n\nconst app = new Hono();\n\nconst authConfig = {\n  jwtAlg: 'HS256' as const,\n  jwtAccessSecret: process.env.JWT_ACCESS_SECRET,\n  authBaseUrl: process.env.AUTH_BASE_URL!,\n  oauthUserinfoPath: '/oauth/userinfo',\n  oauthUserinfoTimeoutMs: 2000,\n};\n\napp.get('/health', (c) => c.json({ status: 'ok' }));\n\napp.use('/api/*', authMiddlewareChain({\n  authConfig,\n  clientId: {},\n  enforce: { requiredScopes: [] },\n}));\n\napp.get('/api/me', (c) => {\n  const auth = c.get('auth');\n  const clientId = c.get('clientId');\n  return c.json({ userId: auth.userId, clientId, scope: auth.scope, tokenType: auth.tokenType });\n});\n```\n\n### Step-by-step middlewares\n\n```typescript\nimport { authMiddleware, clientIdMiddleware, enforceClientScopeMiddleware } from '@autolabz/service-auth-hono';\n\napp.use('/api/*', authMiddleware(authConfig));\napp.use('/api/*', clientIdMiddleware({}));\napp.use('/api/*', enforceClientScopeMiddleware(authConfig, { requiredScopes: ['data'] }));\n\napp.get('/api/me', (c) => c.json({ userId: c.get('auth').userId }));\n```\n\n### Request verification (no middleware)\n\n```typescript\nimport { verifyRequest, verifyRequestWithScopes } from '@autolabz/service-auth-hono';\n\napp.get('/api/me', async (c) => {\n  const result = await verifyRequest(c.req.raw, authConfig);\n  if (!result.success) {\n    return c.json({ error: result.error }, 401);\n  }\n  return c.json({ userId: result.auth.userId });\n});\n```\n\n### AuthBridge for downstream SDKs\n\n```typescript\nimport { makeAuthBridgeFromContext } from '@autolabz/service-auth-hono';\nimport { createDataClient } from '@autolabz/data-sdk';\n\napp.get('/api/data', async (c) => {\n  const auth = makeAuthBridgeFromContext(c, {\n    onUnauthorized: () => console.warn('Downstream 401'),\n  });\n  const client = createDataClient({ baseURL: env.DATA_BASE_URL, auth });\n  const data = await client.get('/v1/data/my-key');\n  return c.json(data);\n});\n```\n\n## API\n\n- `verifyRequest(request, config)` – Verify Request; returns `AuthResult`\n- `verifyRequestWithScopes(request, config, requiredScopes)` – Verify + scope check\n- `authMiddleware(config)` – Bearer + JWT/userinfo; sets `c.set('auth')`\n- `clientIdMiddleware(options?)` – X-Client-Id / client_id query; sets `c.set('clientId')`\n- `enforceClientScopeMiddleware(config, enforceOptions?)` – iss/aud/client/scope check\n- `authMiddlewareChain(options)` – Combined auth + clientId + enforce\n- `makeAuthBridgeFromContext(c, options?)` – AuthBridge for SDK clients\n\n## Context variables\n\nAfter middleware: `c.get('auth')` (AuthPayload), `c.get('clientId')` (string).\n\n## Environment variables\n\nSame as other service-auth adapters:\n\n- `JWT_ALG`: HS256 | RS256\n- `JWT_ACCESS_SECRET`: required for HS256\n- `JWKS_URL`: required for RS256\n- `AUTH_BASE_URL`: OAuth base URL\n- `AUTH_ISSUER`, `OAUTH_USERINFO_TIMEOUT_MS`, `OAUTH_EXPECTED_AUDIENCE`: optional\n\n## License\n\nMIT\n","readmeFilename":"README.md"}