Hono (Cloudflare Workers, Bun, Node, Deno)
Two routes and one middleware. Works the same on every runtime Hono supports.
Register the app first: ask your agent, or create a web app in the dashboard with redirect URI http://localhost:8787/auth/callback.
Environment
On Cloudflare Workers put these in
.dev.varslocally and set the secret withnpx wrangler secret put YOURSELF_CLIENT_SECRET. Elsewhere use.env..dev.varsYOURSELF_ISSUER=https://yourself.mees.sh YOURSELF_CLIENT_ID=app_… YOURSELF_CLIENT_SECRET=ysec_… (shown once when the app was created; rotate it if lost) YOURSELF_REDIRECT_URI=http://localhost:8787/auth/callbackAdd the helper
One file, one dependency (
jose). It does PKCE, state and nonce checks, ID token verification, and a signed session cookie.shnpm install jose curl -fsSL https://yourself.mees.sh/sdk/yourself-auth.ts -o src/yourself-auth.tsWire it up
Register the auth routes before the middleware so they stay public.
src/index.tsimport { Hono } from "hono"; import { createYourselfAuth, type YourselfAuth, type YourselfUser } from "./yourself-auth"; type Bindings = { YOURSELF_ISSUER: string; YOURSELF_CLIENT_ID: string; YOURSELF_CLIENT_SECRET: string; YOURSELF_REDIRECT_URI: string; }; const app = new Hono<{ Bindings: Bindings; Variables: { user: YourselfUser } }>(); let cached: YourselfAuth | undefined; const auth = (env: Bindings) => (cached ??= createYourselfAuth({ issuer: env.YOURSELF_ISSUER, clientId: env.YOURSELF_CLIENT_ID, clientSecret: env.YOURSELF_CLIENT_SECRET, redirectUri: env.YOURSELF_REDIRECT_URI, })); app.get("/auth/login", (c) => auth(c.env).signIn(c.req.raw)); app.get("/auth/callback", (c) => auth(c.env).handleCallback(c.req.raw)); app.post("/auth/logout", (c) => auth(c.env).signOut()); app.use("*", async (c, next) => { const user = await auth(c.env).getUser(c.req.raw); if (!user) return c.redirect(`/auth/login?return_to=${encodeURIComponent(c.req.path)}`); c.set("user", user); await next(); }); app.get("/", (c) => c.text(`Hello, ${c.get("user").name}`)); export default app;Not on Workers?
On Node or Bun, read the variables from
process.envinstead ofc.env:const env = process.env as Bindingsand pass that toauth(env).Check it works
Start the app and open it. You're sent to yourself, sign in with your passkey, and land back in the app signed in. The
list_activityMCP tool (or the dashboard) shows anapp.signed_inevent.