Reference · Project API
Sign-in
Sign people in with a standard OAuth 2.0 PKCE exchange against the project’s own routes, and get a bearer session token back.
- CLI
- —
- In the schema
ext::auth::Identity
PKCE application sign-in flow#
In TypeScript and Dart, SignIn from the client SDK runs the three PKCE steps for you and keeps the session. See sign-in in the TypeScript SDK. The steps below show the flow for any other language.
S256 PKCE across every factor
OAuth and OIDC redirects, passwords, magic links and WebAuthn passkeys all exchange a one-time authorization code and PKCE verifier for ext::auth::Identity tokens.
Time- and tool-scoped agent grants
OAuth 2.1 consent mints revocable ext::napalm::AgentGrant sessions optionally restricted to read-only posture and an allowedQueries allowlist.
Generate a PKCE verifier and challenge
Store a cryptographically random 32-byte
verifierin session storage and compute its base64url-encoded SHA-256 digest as thechallenge.Browser clientconst verifier = base64url(crypto.getRandomValues(new Uint8Array(32)))const challenge = base64url(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier)))const back = encodeURIComponent('https://app.example.com/signed-in')location.href = `https://notes.napalmdata.com/sign-in/authorize?provider=builtin::oauth_github&redirect_to=${back}&challenge=${challenge}`Authenticate the user
For OAuth or OpenID Connect providers,
GET /sign-in/authorizeredirects the user to the provider and back through/sign-in/callbackto your allowedredirect_toURL with an authorizationcode. For email/password, magic links or WebAuthn passkeys, POST directly to the corresponding factor route listed below with yourchallenge.Exchange the authorization code for a session token
Request · curlcurl "https://notes.napalmdata.com/ sign-in/ token?code=$CODE&verifier=$VERIFIER" Response{ "auth_token": "eyJhbGciOi…", "identity_id": "0192c3f4-6b1a-7d8e-9f00-1a2b3c4d5e6f", "refresh_token": "nsr_…", "expires_in": 3600}Pass
auth_tokeninAuthorization: Bearer <auth_token>on subsequent Project API requests. Keeprefresh_tokento renew the session. Upstream OAuth provider tokens remain inside your database and are never exposed to the client.
See Access and sign-in for configuring providers, SMTP delivery and session lifetimes.
Session renewal and sign-out#
A session lasts as long as the project’s sign-in settings keep people signed in. The session’s auth_token lasts expires_in seconds, which is one hour or less if the session ends sooner. Trade the refresh_token for the next token before the current token expires.
curl -X POST https://notes.napalmdata.com/sign-in/token \ -H "Content-Type: application/json" \ -d '{ "grant_type": "refresh_token", "refresh_token": "nsr_…" }'The answer has the same four fields, including a new refresh_token, and the traded refresh token is retired. Napalm accepts the old token again for 30 seconds so a retry can recover a lost answer. Using the old token after those 30 seconds ends the session, so a copied token is caught.
POST /sign-in/revoke- Ends a session. Pass its
refresh_tokenorauth_tokenastoken. Both tokens are refused from then on, and open streams on the session end withsession_ended. POST /sign-in/revoke-all- Ends every session of the person who owns the session in
token. Both routes answer200with an empty body for any token, so neither route reveals whether a token was real. - A token for a page
- A server that holds the session trades the session’s
auth_tokenatPOST /sign-in/tokenwithgrant_type=urn:ietf:params:oauth:grant-type:token-exchange,subject_tokenandsubject_token_type=urn:ietf:params:oauth:token-type:access_token. The answer is a five-minute token of the same session for the browser. The page token can read, and withscope=database:writecan also write. A page token cannot be traded, renewed or used to sign out. - Refusals
- The revocation and token routes follow OAuth for refusals and answer
400with{"error", "error_description"}. The codes areinvalid_grant(an ended session, a spent or unknown token),invalid_request,invalid_scopeandunsupported_grant_type. - On a stream
- A stream ends with
token_expiredthirty seconds before its token runs out. Reconnect with the next token and the stream’s bookmark to continue from the same point. The client libraries reconnect automatically.
{ "access_token": "eyJhbGciOi…", "issued_token_type": "urn:ietf:params:oauth:token-type:access_token", "token_type": "Bearer", "expires_in": 300}OAuth 2.1 agent delegation#
End users can connect external OAuth-enabled AI clients (such as Claude and ChatGPT connectors) directly to your project’s MCP server so an agent can act on their behalf. When an unauthenticated MCP client connects to /mcp, the 401 response points the client to your project’s OAuth 2.1 metadata (/). To enable agent delegation, set agentConsentUrl in your project’s endpoint settings to a consent screen in your web app.
Redirect to your application’s consent page
When an agent initiates
GET /, Napalm forwards the browser to yoursign-in/ agents/ authorize agentConsentUrlwith a signed?request=parameter. Decode the first base64url segment to display the requestingclient_nameandredirect_uri.An agent can request a narrower grant in
scope:database:readasks for read-only access, andquery:followed by a deployed query’s name asks for that query (such asquery:listNotes). Napalm ignores unrecognized scope values, so an agent’s default scope never blocks sign-in, while aquery:value for a query unavailable to agents redirects back witherror=invalid_scope. Scopes cannot set globals, so the user always picks the tenant on your consent page rather than the agent.Approve or deny the grant
The signed-in user selects read-only or read-write access and an expiration window (1, 7, 30 or 90 days). Your consent page posts the user’s decision to
POST /(orsign-in/ agents/ allow POST /) with the user’s own session token.sign-in/ agents/ deny Fetch the agent’s requested permissions with
GET /and the user’s session token. The response returnssign-in/ agents/ request?request=… asked(read,writeorunsaid),askedQueries(the agent’s list, or null), the branch’sgrantGlobalsandqueries.querieslists the deployed queries the branch offers agents, each withname,descriptionandisWrite(filtered toaskedQuerieswhen the agent requested specific queries). Both the signedrequestparameter and the user’s session token are required.To restrict the agent to chosen tools, pass selected names from
queriesasallowedQueries(an empty array is rejected). The grant can then call only those queries, and any other query returns403 forbidden. OmitallowedQueriesto allow every deployed query, or to acceptaskedQuerieswhen the agent supplied a list. A grant cannot widen the agent’s request, so every name inallowedQueriesmust come fromaskedQuerieswhen present, and an agent that requested read access always receives a read-only grant.To hold the agent to one tenant of your app, send the user’s pick in
globals:{ 'default::current_org': organization.id }. Each name must be one of the branch’sgrantGlobals. Because the user chooses the value, read such a global in adenyrule alone. See Grants held to one tenant.To cap how often the agent calls, pass
callBudget, such as{ calls: 1000, period: 'hour' }. Budgets accept 1 to 1,000,000,000 calls per UTC clock hour or day, and values outside that range are rejected. Calls past the budget are refused until the next UTC period starts, and unknown fields in the request body are rejected.Consent page handler// On your consent page, with the user signed in and ?request= from the query string:const request = new URL(location.href).searchParams.get('request')const sealed = JSON.parse(atob(request.split('.')[0].replace(/-/g, '+').replace(/_/g, '/')))// sealed.client_name and sealed.redirect_uri name the agent and the agent's return address.const asked = await (await fetch(`https://notes.napalmdata.com/sign-in/agents/request?request=${encodeURIComponent(request)}`, { headers: { Authorization: `Bearer ${session}` },})).json()// asked.asked is 'read', 'write' or 'unsaid'. asked.askedQueries is the agent's list, or null.// asked.queries holds the queries to offer, and asked.grantGlobals the globals the user may set.const answer = await fetch('https://notes.napalmdata.com/sign-in/agents/allow', { method: 'POST', headers: { Authorization: `Bearer ${session}`, 'Content-Type': 'application/json' }, // allowedQueries is optional: left out, the agent may call every deployed query or the agent's own list. body: JSON.stringify({ request, isReadOnly: true, days: 30, allowedQueries: ['listNotes'] }),})location.href = (await answer.json()).redirectToToken issuance and renewal
Napalm redirects the browser back to the agent with a PKCE authorization code. The agent exchanges the code at
POST /for a 1-hour access token and a renewable refresh token. The response’ssign-in/ agents/ token scopelists the granted permissions:database:readordatabase:write, followed byquery:<name>for each allowed query. Renewing the token preserves the grant’s scope.
Every approved connection creates an ext::napalm::AgentGrant record in your database (exposed on agent requests via global ext::napalm::ClientTokenAgentGrant). Each person can read only their own grants, and deleting a grant revokes the agent’s access immediately. Because API statements cannot reference the grant type directly, declare an alias over it in your schema and query the alias instead, as Watching and stopping an agent shows.
Sign-in route reference#
| Method & route | Description |
|---|---|
GET /sign-in# | Returns public branding metadata (app name, logos, accent color) and enabled sign-in providers. |
GET /sign-in/authorize# | Starts an OAuth or OIDC sign-in redirect with PKCE challenge, provider and redirect_to. |
GET /sign-in/callback# | Receives the OAuth/OIDC callback. Register the callback route with upstream identity providers. |
GET /sign-in/token# | Exchanges a one-time authorization code and PKCE verifier for a session: auth_token, identity_id, refresh_token and expires_in. |
POST /sign-in/token# | Renews a session with its refresh_token, or trades a session token for a five-minute page token. |
POST /sign-in/revoke# | Ends a session given its refresh token or auth token. |
POST /sign-in/revoke-all# | Ends every session of the person on every device. |
GET /sign-in/cli# | Completes browser sign-in for your generated project CLI (delivers the code locally or displays it for SSH). |
GET /# | Starts OAuth 2.1 authorization for AI agents and redirects to your agentConsentUrl. scope may ask for database:read and for individual deployed queries via query:<name>. |
GET /# | Returns the agent’s requested permissions, the branch’s grantGlobals and the deployed queries offered to agents (request, authenticated with the user’s session token). |
POST /# | Approves an agent consent request using the user’s session token (request, isReadOnly, days and optional allowedQueries, globals and callBudget). |
POST /# | Denies an agent consent request (request). |
POST /# | Issues OAuth 2.1 tokens for authorization-code exchange, refresh-token renewal and action handlers exchanging a call assertion for a session (RFC 8693). |
POST /# | Registers OAuth 2.1 agent clients dynamically (RFC 7591). |
POST /# | Revokes the calling OAuth 2.1 agent’s grant token. |
POST /sign-in/register# | Registers a new user account with email and password. |
POST /# | Signs in an existing user with email and password. |
POST /sign-in/verify# | Confirms an email address with a verification code or a verification link’s token. |
POST /# | Sends the verification code or link again. |
POST /# | Sends a password-reset email. |
POST /# | Completes a password reset with the reset code or the reset link’s token. |
POST /# | Signs a new user up by magic link. |
POST /# | Sends a magic link to an existing user. |
GET | POST /# | Completes a magic link sign-in with the code or the link’s token. |
GET /# | Generates a WebAuthn passkey registration challenge. |
POST /# | Verifies and stores a newly registered passkey credential (pass options.user.id as user_handle). |
GET /# | Generates a WebAuthn passkey assertion challenge. |
POST /# | Completes sign-in using a signed WebAuthn passkey assertion. |