When an AI agent needs a user’s data or a scope outside its pre-authorized list, AAuth switches from direct token issuance to a three-step consent flow. First, POST /aauth/agent/token (request_type=auth) answers HTTP 200 with a 600-second request_token and an authorization_uri. Second, the user reviews and optionally narrows each requested scope on a CSRF-protected consent page restricted to members of that organization. Third, LumoAuth redirects back with a single-use 60-second authorization code bound to the exact agent, delegate, key thumbprint and redirect URI.
TL;DR
- User consent runs when User-in-the-loop authorization is on and the request asks for an identity scope, asks for a scope outside Pre-authorized scopes, or has no pre-authorized list.
- Consent starts with HTTP
200, returningrequest_token(600 s, single-use) andauthorization_uri; HTTP401is always an authentication failure, never a consent prompt. /orgs/{orgId}/portal/aauth/authorizevalidates CSRF, refuses any signed-in user outside the route organization with403, rejects tampered scopes, and turns “all switches off + Authorize” intoerror=access_denied.- Authorization codes expire after 60 seconds and use an atomic SQL
UPDATE(WHERE used = false) so concurrent redemptions never yield two tokens. - Redeeming the code (
request_type=code) verifies the agent, delegate,redirect_uri, organization and thecnfkey thumbprint captured at request time, returning one genericinvalid_grantmessage on any mismatch.
When does AAuth ask a person for consent?
If you are starting Series 2 here, read What is AAuth? for the full protocol picture and Pseudonymous, identified, authorized for how consent records affect user identity claims.
Two settings on the agent’s registration control whether request_type=auth issues an auth token immediately or returns a consent URL:
- User-in-the-loop authorization (
userAuthorizationEnabled, off by default) - Pre-authorized scopes (
allowedScopes)
When User-in-the-loop authorization is on, LumoAuth asks a user to consent if any of these four conditions holds:
- The resource token requests any identity scope (
openid,profile,email,phoneoraddress). - The resource token requests any scope outside the agent’s Pre-authorized scopes.
- The resource token carries no scopes.
- The agent has no Pre-authorized scopes configured.
Only when the request names at least one scope, every named scope is in Pre-authorized scopes, and none is an identity scope does LumoAuth skip consent and issue an auth+jwt directly.
Step 1: Request authorization and get a 600-second request_token
When consent may be needed, include a redirect_uri in the JSON body of POST /orgs/{orgId}/api/v1/aauth/agent/token. That URI must match one of the agent’s registered Redirect URIs byte for byte; omitting it returns 400 invalid_request, and sending an unregistered URI returns 400 invalid_redirect_uri.
POST /orgs/acme-corp/api/v1/aauth/agent/token HTTP/1.1
Host: app.lumoauth.dev
Content-Type: application/json
Content-Digest: sha-256=:<base64-sha256-of-body>:
Agent-Auth: agent_token=eyJhbGciOiJSUzI1NiIsInR5cCI6ImFnZW50K2p3dCIsImtpZCI6ImtleS0xIn0...
Signature-Input: sig1=("@method" "@authority" "@path" "signature-key" "content-digest" "content-type" "authorization");created=1796256000;nonce="9kP2xR8mQ1vT4wY7nB3cZA"
Signature: sig1=:<base64url-signature-bytes>:
{
"request_type": "auth",
"resource_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6InJlc291cmNlK2p3dCIsImtpZCI6ImtleS0xIn0...",
"redirect_uri": "https://email-agent.aiservices.com/oauth/callback"
}
Notice that scopes still come from the resource_token claim, not from the request body. When user consent is required, LumoAuth creates a 32-byte random request_token, stores its SHA-256 hash alongside the agent’s cnf public key, delegate, scopes and redirect_uri, and responds with HTTP 200:
{
"request_type": "auth",
"request_token": "8vN4pQ2xK9mR1wT7yB3cZ6hJ5dF0sL2nG4aE1uV8qW0",
"authorization_uri": "https://app.lumoauth.dev/orgs/acme-corp/portal/aauth/authorize?request_token=8vN4pQ2xK9mR1wT7yB3cZ6hJ5dF0sL2nG4aE1uV8qW0",
"expires_in": 600
}
Check for authorization_uri (or the absence of auth_token) on a 200 response. A 401 (authentication_required) always means that the signature or agent+jwt failed, never that the user must consent. LumoAuth also exposes GET /orgs/{orgId}/api/v1/aauth/agent/auth?request_token=…, which redirects the browser to the same portal consent URL.
Step 2: Send the user to the consent screen
Redirect the user’s browser to authorization_uri. If the person is not signed in yet, LumoAuth sends them to the organization sign-in page and brings them right back to /orgs/{orgId}/portal/aauth/authorize once they authenticate.
Four safeguards protect the consent page before any code is minted:
- Cross-organization refusal (
403). On bothGETandPOST, LumoAuth checks that the signed-in user is a member of the route organization and that therequest_tokenbelongs to that same organization. A user signed in to another organization gets403 Access Denied— with no fallback even for a platform administrator, because consent mints a user token inside that organization. - CSRF protection.
POST /orgs/{orgId}/portal/aauth/authorizevalidates the_csrf_tokentied toaauth_authorizebefore touching the request token. - Atomic single-use request token. Both Authorize and Deny claim the
request_tokenwith one conditional SQLUPDATE(WHERE consumed = false AND expires_at > now). Two simultaneous form submissions cannot produce two authorization codes or let both an approval and a denial pass. - Strict scope narrowing. The consent page shows Agent, Wants to access, optional Acting as delegate, Permissions requested (one toggle switch per requested scope, all on by default) and Authorizing as.
- A tampered
POSTnaming any scope outside the stored request is rejected and returns to the consent page, rather than silently trimming extras. - Turning every switch off and clicking Authorize does not mean “grant everything”. A hidden
scopes_shown=1field distinguishes “user turned every switch off” from a malformed form missing the list. With all switches off, LumoAuth consumes therequest_token, auditsaauth.authorization_denied(reason: "nothing_granted"), and redirects back with?error=access_denied&error_description=User+granted+no+permission.
- A tampered
When the user clicks Deny, LumoAuth consumes the request_token, audits aauth.authorization_denied, and redirects to:
https://email-agent.aiservices.com/oauth/callback?error=access_denied&error_description=User+denied+authorization
When the user clicks Authorize with at least one requested scope kept on, LumoAuth consumes the request_token, creates a 60-second authorization code, audits aauth.authorization_granted, and redirects to:
https://email-agent.aiservices.com/oauth/callback?code=c5K9mP2rT8vW1xZ4nB7qF0hJ3dL6sA2eG5uY8wC1kR4
Step 3: Redeem the 60-second code and pass all binding checks
Your callback handler extracts code and sends a signed request_type=code call to POST /orgs/{orgId}/api/v1/aauth/agent/token, carrying the same Agent-Auth: agent_token=<JWT> header and signed by the same private key:
POST /orgs/acme-corp/api/v1/aauth/agent/token HTTP/1.1
Host: app.lumoauth.dev
Content-Type: application/json
Content-Digest: sha-256=:<base64-sha256-of-body>:
Agent-Auth: agent_token=eyJhbGciOiJSUzI1NiIsInR5cCI6ImFnZW50K2p3dCIsImtpZCI6ImtleS0xIn0...
Signature-Input: sig1=("@method" "@authority" "@path" "signature-key" "content-digest" "content-type" "authorization");created=1796256025;nonce="4mR8wT2xK1pN9qV5bC7dEA"
Signature: sig1=:<base64url-signature-bytes>:
{
"request_type": "code",
"code": "c5K9mP2rT8vW1xZ4nB7qF0hJ3dL6sA2eG5uY8wC1kR4",
"redirect_uri": "https://email-agent.aiservices.com/oauth/callback"
}
On success, LumoAuth returns 200 with the key-bound auth+jwt and, unless refresh tokens are disabled for the agent, a 30-day refresh_token:
{
"request_type": "code",
"auth_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6ImF1dGgrand0Iiwia2lkIjoia2V5LTEifQ...",
"token_type": "auth+jwt",
"expires_in": 3600,
"refresh_token": "aauth_refresh_..."
}
Before issuing that token, LumoAuth enforces eight checks. Every binding failure returns the same generic 400 invalid_grant description (The authorization code is invalid, expired, or not bound to this agent) so a caller cannot probe which check failed; the real reason is recorded in the audit log under aauth.agent_token_rejected.
| Check | What LumoAuth verifies | Why it matters |
|---|---|---|
| 1. Active agent | The agent registration still exists and is active (400 unauthorized_agent otherwise) |
A suspended or deleted agent cannot redeem a code issued moments earlier |
| 2. Atomic single-use & 60 s TTL | Lookup by SHA-256 hash, not expired, claimed via UPDATE … WHERE used = false |
Stops replay and concurrent-redemption races |
3. Exact redirect_uri |
Matches the redirect_uri saved when the request token was created |
Blocks redirect-URI substitution |
| 4. Route organization | Code lookup is scoped to the route organization | Prevents cross-organization code replay even if identifiers collide |
| 5. Agent identifier | Matches the iss of the redeeming agent+jwt |
Prevents another agent from redeeming the code |
| 6. Delegate identifier | Matches sub of the redeeming agent+jwt (or null when no delegate was used) |
Stops one session delegate from stealing another session’s code |
7. Key thumbprint (cnf) |
Constant-time equality between the RFC 7638 thumbprint of the stored public key and the redeeming token’s cnf thumbprint |
Stops redemption even by the same agent under a different key pair |
| 8. Consenting user | The user still exists, belongs to the route organization, and matches the organization recorded at consent time | Prevents cross-organization leakage and stops codes for removed users |
Redeeming this code also flips used = true on the stored AAuthAuthorizationCode row for (organization, user, agent, resource). As explained in Pseudonymous, identified, authorized, that redeemed record is the exact consent evidence that unlocks real user sub, profile and email claims for resources using the default authorized level.
Calling both steps in Python, Node and Go
With the Python SDK (lumoauth[aauth]), request_authorization() detects the 200 consent response for you and sets authorization_required: True alongside auth_url. Once your callback receives code, call exchange_code() with the same redirect_uri and agent_token:
from lumoauth import AAuthClient
client = AAuthClient(
agent_identifier="https://email-agent.aiservices.com",
private_key_pem=private_pem,
org_id="acme-corp",
)
REDIRECT_URI = "https://email-agent.aiservices.com/oauth/callback"
# Step 1: start authorization
res = client.request_authorization(
resource_token=resource_token,
scope="openid email email:read email:send",
agent_token=agent_token,
redirect_uri=REDIRECT_URI,
)
if res.get("authorization_required"):
# Step 2: redirect the user's browser to res["auth_url"]
print("Send user to:", res["auth_url"])
# Step 3: inside your /oauth/callback handler after approval
tokens = client.exchange_code(
received_code,
REDIRECT_URI,
agent_token=agent_token,
)
# Step 4: call the resource with the key-bound auth+jwt
resp = client.signed_request(
"GET",
"https://api.mailservice.com/v1/emails/inbox",
auth_token=tokens["auth_token"],
)
In Node.js (@lumoauth/agent), call client.requestAuthToken(...), check 'authorizationRequired' in result, redirect to result.authorizationUri, and finish with client.exchangeCode({ code, redirectUri, agentToken }). In Go (github.com/lumoauth/lumo-auth-go), call client.RequestAuthToken(...), check result.AuthorizationRequired, redirect to result.AuthorizationURI, and call client.ExchangeCode(...).
How LumoAuth does it
To turn on the consent flow for an AAuth agent in the Organization Portal:
- Register the agent under AI Agents → Agents (
/portal/agents) with AAuth on step 2, and tick User-in-the-loop authorization under Acting for people on step 3. - Open the AAuth credentials tab, edit the agent, and add your exact callback URLs under Redirect URIs. (Redirect URIs are configured on the edit page after creation.)
- On the AAuth resources tab, add human-readable descriptions next to each scope under Scopes, because those exact sentences appear next to each toggle switch on
/portal/aauth/authorize. - Every consent decision writes
aauth.authorization_grantedoraauth.authorization_deniedto Audit logs, and any failed code redemption writesaauth.agent_token_rejectedwith the exact binding mismatch. - End users can inspect and revoke their granted AAuth access at any time from AI agents acting for you (
/account/my-agents).
For the full worked email-agent example, read the AAuth overview. For every error code and binding rule, read the AAuth 1.0 specification, sections 3.1 and 3.2.
Standards involved
- OAuth 2.1, OAuth 2.1 (draft), defining exact redirect URI matching and short-lived single-use authorization codes
- HTTP message signatures, RFC 9421, authenticating both the
request_type=authinitiation and therequest_type=coderedemption - Key thumbprint, RFC 7638, binding the authorization code to the requesting agent token’s
cnfkey - Request body digest, RFC 9530, covering the JSON body on every call to the agent token endpoint
The full list is on the standards reference.
FAQ
Why does LumoAuth return HTTP 200 instead of 401 when user consent is required?
On POST /aauth/agent/token, HTTP 401 (authentication_required) always means that the agent token or HTTP message signature failed verification. When the agent authenticated cleanly but needs a person to approve the request, LumoAuth answers HTTP 200 with request_token, authorization_uri and expires_in set to 600.
How long do AAuth request tokens and authorization codes stay valid?
A request_token stays valid for 600 seconds (10 minutes) and is consumed atomically on the first Authorize or Deny submission. Once the user approves, the authorization code stays valid for 60 seconds and is single-use under an atomic database update.
What happens if a user switches off every permission and clicks Authorize?
LumoAuth treats an approval with every requested scope switched off as a denial, never as a grant of all scopes. It consumes the request_token, logs aauth.authorization_denied with reason nothing_granted, and redirects back to the agent with error=access_denied and no authorization code.
Can a user signed in to a different organization approve an AAuth consent request?
No. Both GET and POST on /orgs/{orgId}/portal/aauth/authorize verify that the signed-in user belongs to the route organization and that the request_token belongs to that same organization. Any cross-organization session receives 403 Access Denied, even for a platform administrator.
What does LumoAuth check when an agent redeems a 60-second authorization code?
LumoAuth checks that the agent registration is still active and atomically marks the code as used. It then verifies six bindings: route organization, user organization, exact redirect_uri, agent identifier, delegate identifier and the SHA-256 thumbprint of the agent token’s cnf key.
Does redeeming an AAuth authorization code also enable real user identity claims?
Yes. When a resource uses the default authorized auth level, a redeemed authorization code for that organization, user, agent and resource serves as the explicit consent record. LumoAuth then includes real sub, profile and email claims instead of failing closed to a pairwise pseudonym.
Related: AI agent identity and human-in-the-loop approvals on the solutions pages, What is AAuth? and The end-user side: “My agents” and revoking what acts for you on this blog.
Build your first signed AAuth flow with the AAuth quickstart.