Astro (server output)
Endpoints for sign-in and middleware that guards every page.
Register the app first: ask your agent, or create a web app in the dashboard with redirect URI http://localhost:4321/auth/callback.
Environment
.envYOURSELF_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:4321/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/lib/yourself-auth.tsConfigure it
src/lib/auth.tsimport { createYourselfAuth } from "./yourself-auth"; export const auth = createYourselfAuth({ issuer: import.meta.env.YOURSELF_ISSUER!, clientId: import.meta.env.YOURSELF_CLIENT_ID!, clientSecret: import.meta.env.YOURSELF_CLIENT_SECRET!, redirectUri: import.meta.env.YOURSELF_REDIRECT_URI!, });Endpoints
src/pages/auth/[action].tsimport type { APIRoute } from "astro"; import { auth } from "../../lib/auth"; export const GET: APIRoute = ({ request, params }) => { if (params.action === "login") return auth.signIn(request); if (params.action === "callback") return auth.handleCallback(request); return new Response("Not found", { status: 404 }); }; export const POST: APIRoute = ({ params }) => params.action === "logout" ? auth.signOut() : new Response("Not found", { status: 404 });Guard every page
src/middleware.tsimport { defineMiddleware } from "astro:middleware"; import { auth } from "./lib/auth"; export const onRequest = defineMiddleware(async (context, next) => { if (context.url.pathname.startsWith("/auth/")) return next(); const user = await auth.getUser(context.request); if (!user) return context.redirect(`/auth/login?return_to=${encodeURIComponent(context.url.pathname)}`); context.locals.user = user; return next(); });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.