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 PKCE flow for you and persists the session. See sign-in in the TypeScript SDK.
PKCE across every factor
OAuth, passwords, magic links and passkeys all exchange a PKCE authorization code.
Scoped agent grants
Consent grants restrict agent tokens by allowed queries, read-only mode and expiry.
When integrating from another language or custom backend, run the three PKCE steps directly against your project’s /sign-in routes.
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 runs for the lifetime configured in your project’s sign-in settings. The session’s auth_token lasts expires_in seconds (up to one hour, or less if the session ends sooner). Exchange refresh_token at POST /sign-in/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 response returns the same four fields with a new refresh_token and retires the previous refresh token. Napalm accepts the retired refresh token for 30 seconds so a retry can recover a lost response. Replaying a retired refresh token after 30 seconds revokes the entire session.
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 active session belonging to the user identified by
token. Both revocation routes return200with an empty body for any input so neither route leaks whether a token was valid. - Browser page tokens
- A server holding a session can exchange
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 response returns a 5-minute browser token bound to the same session. Page tokens are read-only by default, acceptscope=database:writefor writes and cannot be exchanged, renewed or used to sign out. - Refusals
- Token and revocation routes return OAuth error responses (
400with{"error", "error_description"}):invalid_grant(expired session, spent code or unknown token),invalid_request,invalid_scopeandunsupported_grant_type. - Live stream expiry
- Open live streams close with
token_expired30 seconds before the bearer token expires. Reconnect with a renewed token and the stream’s bookmark to resume from the same position. Napalm’s client libraries reconnect automatically.
Exchanging a session token for a short-lived browser page token returns an OAuth 2.0 token-exchange response.
{ "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 workspace or 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 scope the agent to one root or workspace in your app, pass the user’s choice in
globals, such as{ 'default::current_org': organization.id }. Each key must appear in the branch’sgrantGlobals. Because the user supplies the value directly, reference grant globals only indenyrules. See Scoping grants with consent globals.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 identify the agent and its callback URL.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 lists available queries, and asked.grantGlobals lists 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' }, // Omit allowedQueries to grant every available query (or the agent's askedQueries 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. Declare a schema alias over ext::napalm::AgentGrant so signed-in users can list and delete active grants, 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. |