Passkin

OAuth and MCP: apps, agents and services asking your users for access

Status: built (2026-10-05). Tests: apps/auth-broker/tests/oauth.test.ts, apps/auth-broker/tests/device.test.ts, packages/nextjs/tests/resource.test.ts.

Your project already signs people in to your own applications. This is the other direction: someone else's program — an AI agent connecting to your MCP server, a partner's app, a script, one of your own services — asks one of your users for access to your API, the user is shown who is asking and for what, says yes, and the program gets a token it can use at your API and nowhere else. It is OAuth 2.1 as the MCP authorization specification uses it; Clerk, Stytch and WorkOS sell the same thing.

Nothing here is on until you turn it on (dashboard → OAuth & MCP, or PATCH /v1/manage/projects/:pid/oauth/settings).

The pieces

Resource An API or MCP server you protect, identified by its URL (RFC 8707). It defines scopes — read:orders, with a sentence the person will read. A token is issued for one resource and is worth nothing at another
Client A program that may ask. Four kinds, below
Grant What one person allowed one client, for one resource. One row, widened when the client asks for more. Taking it back ends everything it started
Machine client A service of yours with its own secret, for client_credentials: no person, no consent screen

Where clients come from

  1. Registered by you in the dashboard or API (POST …/oauth/clients). A public client (a program on a device, held to PKCE) or a confidential one (a server, with a secret shown once). You may mark one first_party — your own program — and its users are not asked to consent; nothing else can set that.
  2. Dynamic registration (RFC 7591, POST /p/<pk>/register) — how most MCP clients arrive. Off by default. The client registers itself and is shown to people as "not verified". It can register only public or confidential clients for the authorization-code or device-code flow (never client_credentials), only redirect URLs of the allowed kinds, is limited per address and per project, and is removed after 30 days unless someone holds a grant from it.
  3. A metadata document (client_id is an https URL of a page the client controls). Off by default. Passkin fetches it through its guarded fetch (public hosts only, https, no redirects, 1 MB), requires its client_id to be its own address, refuses a secret or keys in it, reads it again every ten minutes, and shows the person "identified by agent.example — Passkin has not verified it".
  4. Machines — made by you, never by the client itself.

The flow (authorization code with PKCE)

GET  https://auth.passk.in/p/<pk>/authorize
       ?client_id=oc_…  &redirect_uri=https://agent.example/callback  &response_type=code
       &scope=read:orders write:orders  &resource=https://api.example.com/mcp
       &code_challenge=…  &code_challenge_method=S256  &state=…

The person signs in to your project as always (any method you enabled), then sees a page that says who is asking (name, where they go next, how far that is vouched for), what it will be able to do (the descriptions you wrote), and for which resource. They press Allow or Cancel. Passkin redirects back with code and iss. The client redeems it at POST /p/<pk>/token with its code_verifier:

{ "access_token": "eyJ…", "token_type": "Bearer", "expires_in": 600, "scope": "read:orders", "refresh_token": "rt_…", "id_token": "eyJ…" }
  • The access token is a JWT (typ: at+jwt) signed by the project: aud is the resource, scope, client_id, sub the person, sid the session. With no resource it is for the project itself ("sign in with this project's accounts"; aud is the publishable key, userinfo works) and only openid profile email offline_access apply.
  • The id_token comes with openid. Your claim templates are not applied to a third party's tokens — they exist for your own site, and a third party would receive whatever you put there, private metadata included.
  • prompt=none answers login_required or consent_required and never a page. prompt=consent asks again.
  • Asked once. The same request again goes straight through; a request for more scopes asks again.

What is checked

  • PKCE (S256) is required of every client. A secret is never accepted from a public client (a secret inside a program people run is a secret everyone has).
  • Redirect URLs: exact match, or the same loopback address on any port (RFC 8252). Anything else is an error page, never a redirect.
  • Scopes must be defined by the resource and allowed to the client; unknown ones are refused, not dropped. Scopes other than Passkin's identity scopes need a resource. With a resource and no scope, the client gets the scopes it may have.
  • The code is one try, bound to its client, redirect URL and verifier; presenting it twice ends the session it started.
  • Nothing is issued before the person has seen the consent page. Allow counts only if that page was put in front of them in this sign-in (a passkey offer is not consent).
  • Refresh tokens rotate, belong to their client (not to your website, not to another client), can be narrowed but never widened, and a spent one coming back ends the session.
  • Taking access back is immediate for refresh and introspection; a verified-locally access token lives until it expires (default 10 minutes, at most 1 hour for a third party).

Device authorization (RFC 8628): a program with no browser

A command line, a TV, an agent on a server: it cannot open a page, so it asks for a code, shows it, and polls while the person approves on their own phone or computer. Per client, off until you tick device code (or send device_flow: true); a client that only ever starts from a terminal may have no redirect URL at all. A self-registered client (RFC 7591) may ask for the grant too, by listing urn:ietf:params:oauth:grant-type:device_code in grant_types.

# 1. The device asks (a public client sends client_id; a confidential one authenticates as at the token endpoint)
curl https://auth.passk.in/p/$PK/device_authorization -d client_id=$CLIENT_ID -d scope=read:orders -d resource=https://api.example.com/mcp
# → { "device_code": "dc_…", "user_code": "BCDF-GHJK", "verification_uri": "https://auth.passk.in/p/<pk>/device",
#     "verification_uri_complete": "…/device?user_code=BCDF-GHJK", "expires_in": 600, "interval": 5 }

# 2. It shows verification_uri and user_code, then polls every `interval` seconds
curl https://auth.passk.in/p/$PK/token -d grant_type=urn:ietf:params:oauth:grant-type:device_code -d device_code=dc_… -d client_id=$CLIENT_ID
# → 400 authorization_pending | slow_down | access_denied | expired_token, or 200 with the same tokens as the authorization-code flow

The person opens the address, types the code, signs in to your project as always, and sees the same consent page — who is asking, what for, which resource — with the code repeated and a warning: only continue if you started this on your own device; if someone sent you this code, do not. They press Allow or Cancel, and are told to go back to the device.

  • Always asked. The consent page appears every time, even for a client the person allowed before and even for one you marked first_party: a code is something a stranger can hand over, so a silent yes is never right here.
  • The code is eight letters from BCDFGHJKLMNPQRSTVWXZ (no vowels, nothing that looks like a digit), shown as ABCD-EFGH; typed in any case, with or without the dash. A wrong, spent, expired or other-project code gets the same words. Typing is limited to ten tries per address per ten minutes (and 300 per project): the guesses cannot outrun twenty-to-the-eighth. The link verification_uri_complete only fills the box in; a person still presses Continue.
  • The device code (dc_…) is kept as a hash, lives ten minutes, and is worth one redemption — by the client it was issued to, which must authenticate the same way again. Redeeming it twice, or with another client, gets invalid_grant; after it runs out the device hears expired_token for a minute and invalid_grant after.
  • Polling too fast gets slow_down and the wait grows by five seconds each time. Starting is limited per address (30 per ten minutes) and per project.
  • The form that takes the code accepts only a post from our own origin. Banning the person, taking the grant back, or switching the client off before the device collects stops it.
  • The result is a grant like any other: it is listed under Grants, the person can take it back, and the refresh token rotates and belongs to the client.

Agents: who is acting for whom

When an app or an AI agent holds a token on a person's behalf, the access token says both (RFC 8693 §4.1):

{ "sub": "user_…", "act": { "sub": "oc_…", "name": "Order Agent", "kind": "app" }, "client_id": "oc_…", "aud": "https://api.example.com/mcp", "scope": "read:orders", "sid": "sess_…" }

sub is the person — a resource server that reads only sub treats the call as theirs, as it should; act is the agent holding their authority. kind is app (you registered it), dynamic (it registered itself) or metadata (identified by a document): the last two have not been vouched for, and a resource server may reasonably refuse them the sensitive scopes. The same appears in introspection. In the SDK: caller.actor is { clientId, name, kind } (null for a machine, which acts for no one), and caller.userId is the person. The consent page tells the person the same thing — it will act in your name, and what it does is recorded as done by it on your behalf — and the person's list of apps and agents (/v1/me/authorizations) is where they take it back.

  • Short-lived by design. Give an agent its own token lifetime — access_token_ttl_seconds, 60 to 3600 (the dashboard's Token lifetime, the API, passkin.config.json); null is the project's default, which is capped at an hour for any third party anyway. A refresh keeps it. A leaked agent token is then good for minutes, and taking the grant back ends refresh at once.
  • Scoped by the developer, then by the person. A client may hold only the scopes and resources you allowed it, and a person sees and approves exactly those before anything is issued.
  • Recorded. Each grant (who allowed which agent, for what) is in the audit log (oauth.grant.created), the agent's last use is on the grant, and act carries the agent into your own API's logs.
  • Impersonation (support staff acting as a user, IMPERSONATION.md) uses the same act claim on the project's own tokens; a third party's token is never an impersonation, so the two never meet.

DPoP: a token that is useless without its key (RFC 9449)

A bearer token works for whoever holds it. For a public client — a CLI on a laptop, an agent in a container, a desktop app — that is the weak point: the token sits in a file or a log. With DPoP the client holds a private key and proves possession on every request, so a copied token is worthless without it.

At the token endpoint. A client sends a DPoP header: a JWT (typ: dpop+jwt, signed ES256, ES384, RS256, PS256 or EdDSA, the public key in the header's jwk) whose claims name this request: htm (POST), htu (the token endpoint's address, no query), a fresh iat and a unique jti. Passkin answers with "token_type": "DPoP" and an access token carrying cnf: { "jkt": <thumbprint of the key> }. The refresh token is bound to the same key: a refresh without a proof from it is refused before the token is touched, so a thief holding only the refresh token neither gets in nor uses up the real client's. Every kind of grant works (authorization code, device code, refresh, client_credentials).

At your API. The client sends Authorization: DPoP <token> and a DPoP header with a new proof naming that request's method and address and the token (ath). With the SDK, switch it on and the rest is checked for you:

const mcp = createResourceServer({ resource: "https://api.example.com/mcp", /* … */ dpop: { required: false } });
// caller.boundTo is the key's thumbprint when the request was DPoP; a bound token presented as a plain bearer token is refused with 401 invalid_token

The challenge it sends says which algorithms it takes (WWW-Authenticate: Bearer …, DPoP algs="…"). Behind a proxy that rewrites the address, give dpop.url the public one; with more than one instance or in serverless functions, give dpop.replay a store they share (the default remembers proofs in memory, which is right for one process only). dpop.required: true refuses any token that is not bound. Not using the SDK? Verify the proof with the same function, verifyDpopProof from @passkin/server, and check cnf.jkt equals the proof key's thumbprint.

  • Replay: each proof is good once (kept five minutes at the token endpoint, by key and jti). A proof must be signed with a public jwk and at most 60 seconds old; one that names a token where there is none, or none where there is one, is refused.
  • Require it per client — dashboard (Require proof of possession), require_dpop: true in the API or passkin.config.json: such a client gets no token without a proof. Advertised as dpop_signing_alg_values_supported in the server metadata; introspection answers token_type: "DPoP" and cnf for a bound token.
  • Where a bound token is not accepted: the OpenID userinfo endpoint and the end-user API (/v1/me) take bearer tokens only, so a bound token presented there is refused — those are for the project's own applications.
  • Not built: server-provided nonces (RFC 9449 §8: a proof's freshness rests on iat and one-use jti instead); binding the authorization code to the key (dpop_jkt, §10), so a stolen code can still be redeemed with another key before the client does — PKCE already protects against that; DPoP for the OpenID userinfo endpoint.

Machine access (client_credentials)

curl -u "$CLIENT_ID:$CLIENT_SECRET" https://auth.passk.in/p/$PK/token \
  -d grant_type=client_credentials -d resource=https://api.example.com/mcp -d scope=read:orders

A machine client names the resources it may call and the scopes it may have (all must exist). Its token has sub = the client, aud = the resource, no sid, no refresh token, no id token; it is never a person's client and a person's client is never a machine. Per-client limit: 600 a minute. Switching the client off stops introspection of its tokens at once.

Protecting your API or MCP server

import { createResourceServer } from "@passkin/nextjs/resource"; // plain Request/Response: Next.js, Hono, Workers, Deno, Bun

const mcp = createResourceServer({ resource: "https://api.example.com/mcp", scopes: ["read:orders"], name: "Orders" });

// GET /.well-known/oauth-protected-resource/mcp  (RFC 9728: tells a client which authorization server to use)
export const GET = () => mcp.metadataResponse();

// POST /mcp
export const POST = mcp.withAuth(async (request, caller) => Response.json({ person: caller.userId }), { scopes: ["read:orders"] });

verify checks the signature against the project's keys, expiry, audience = your resource, and the scopes you require; on failure it hands you the response the specifications ask for: 401 with WWW-Authenticate: Bearer resource_metadata="…" (how an MCP client discovers where to authorize), 401 invalid_token, or 403 insufficient_scope. caller.machine tells a service from a person. With introspect: true (and your secret key) it asks Passkin on every call, so a grant taken back stops working at once instead of at the token's expiry.

Not using the SDK? The same checks by hand: verify the JWT with /p/<pk>/jwks.json, require aud to be your resource, and read scope. Or call POST /p/<pk>/introspect (RFC 7662) with Authorization: Bearer sk_… and token=…: { "active": true, "scope": …, "client_id": …, "sub": …, "aud": … }.

Step-up (RFC 9470)

Access tokens carry acr, amr and auth_time, so an operation can demand a stronger or more recent sign-in than the token shows: mcp.withAuth(handler, { authentication: { acr: MULTI_FACTOR, maxAge: 300 } }) answers 401 insufficient_user_authentication with the acr_values and max_age that would do. See STEP-UP.md.

Discovery

  • GET /.well-known/oauth-authorization-server/p/<pk> (RFC 8414; also /p/<pk>/.well-known/oauth-authorization-server): endpoints (device_authorization_endpoint when third-party access is on), registration_endpoint only when dynamic registration is on, client_id_metadata_document_supported, scopes_supported (including your resources'), code_challenge_methods_supported: ["S256"].
  • The OpenID discovery document at /p/<pk>/.well-known/openid-configuration carries the introspection and registration endpoints too.
  • CORS: the token, revocation, registration and metadata endpoints answer any origin, without credentials (a browser-based MCP client needs it; none of them reads a cookie) — only for projects that switched third-party access on.

For the person

GET /v1/me/authorizations lists the apps and agents they allowed; DELETE /v1/me/authorizations/:id takes access back (and every session and refresh token it started ends). Those sessions are not listed as devices. They are also in the dashboard under OAuth & MCP → Grants, and a ban ends them like any other session.

Management API

Under /v1/manage/projects/:pid/oauth/ (dashboard session or workspace API key): settings, resources, clients (?kind=app|dynamic|metadata|machine, rotate-secret), grants (DELETE to revoke). Audited as oauth.*; oauth.client.created, oauth.grant.created and oauth.grant.revoked are webhook events.

Not built yet

private_key_jwt and mutual-TLS client authentication; client registration management (RFC 7592); rich authorization requests; Cross-App Access; per-client token lifetimes; a hosted consent component (the consent page is Passkin's own hosted page, in English and Arabic); per-agent credentials beyond OAuth clients (an agent registry with its own policies and a call-level audit of your API, which only your server sees). (The token vault for connecting your users' Google or GitHub accounts is built: VAULT.md.) (passkin mcp lets an assistant manage a workspace; see PLATFORM-API.md.)

Ready to try it?

Create a project — the dashboard fills these snippets in with your own keys.

Open the dashboard