People and agents
An app can be called by a person signed in with a cookie or a session token, by an AI agent or other client with an OAuth token the person granted, or by an API key. Some actions only a person should take directly: changing the password, 2FA, or passkeys, confirming their identity for a step-up, linking a sign-in, ending sessions, approving OAuth consent. AuthEndpoints gives every caller a kind, a policy that keeps a route for people, and an opt-in scheme that sends each credential to exactly one handler.
Caller kind
Read it with User.GetCallerKind(). The values are in CallerKinds:
| Kind | Who |
|---|---|
person | The Identity application cookie, an Identity bearer token, or an AuthEndpoints JWT. |
delegated | An OAuth access token from AuthEndpoints.OpenIddict: a client acting for the person, or for a subject the person chose. |
api_key | An API key. |
The kind is the ae:caller claim (CallerKinds.ClaimType) on an identity. The built-in sign-in identities are recognized without it, by their authentication type, so cookies and tokens issued before this existed are people too; the claim is not written into them. AuthEndpoints.OpenIddict adds ae:caller = delegated to every validated access token, and records the acting client in the RFC 8693 act claim, {"client_id":"…"}, next to sub. Read the client with User.GetActingClientId().
A host scheme sets ae:caller on the identities it creates. An identity without it, from a scheme AuthEndpoints does not know, has no kind: GetCallerKind() returns null. To add your own kinds (a service account, a support agent), set the claim from your principal hooks, such as an IUserClaimsPrincipalFactory<TUser> or the authentication handler.
When a policy authenticates with more than one scheme and each succeeds, the principal holds an identity from each. Then any kind other than person wins: a person's cookie sent with an agent's token never makes the token a person.
Keep a route for people
app.MapPost("/billing/close-account", CloseAccount)
.RequireAuthorization("app") // the route's own schemes
.RequireDirectPerson(); // 403 for delegated tokens, API keys, and unknown kinds
builder.Services.AddAuthorization(options => options.AddPolicy("people-only", policy => policy
.AddAuthenticationSchemes(IdentityConstants.ApplicationScheme, OAuthServerServiceCollectionExtensions.ValidationScheme)
.RequireDirectPerson()));
RequireDirectPerson() (DirectPersonRequirement) passes when every authenticated identity is a person. A caller that authenticates as anything else gets 403. It names no authentication scheme, so pair it with the route's own.
Built-in routes that require a person
RequireAuthEndpointsUser() authenticates with the application cookie, Identity bearer, and JWT bearer schemes that are registered, and requires a direct person. These built-in routes use it:
| Area | Routes |
|---|---|
| Password and profile | GET and POST /manage/info, POST /manage/password, POST /resendConfirmationEmail |
| Two-factor | GET and POST /manage/2fa |
| Passkeys | POST /passkeys/creationOptions, and GET, POST, PATCH /passkeys, DELETE /passkeys/{id} |
| ReAuth | POST /confirmIdentity, POST /confirmIdentity/passkeyOptions, POST /confirmIdentity/emailCode/send, GET /manage/authMethods |
| External sign-in | GET /logins, DELETE /logins/{loginProvider}/{providerKey}, GET /link/{scheme}, GET /link/{scheme}/callback |
| Sessions | GET /sessions, DELETE /sessions/{id}, POST /sessions/revokeOthers |
These routes never accepted an OAuth access token, because their schemes do not include the OAuth validation scheme. The requirement makes that rule explicit, and it also refuses a cookie or token whose principal a host tagged with another kind. In AuthEndpoints.OpenIddict, the consent API, the connected apps API, and the developer app API refuse delegated tokens and API keys with 403, even when a host scheme forwards a token to them. AuthEndpoints has no account deletion or API key management routes; put RequireDirectPerson() on yours.
One handler per credential
Authorizing a route with several schemes reads the request with each of them. An optional policy scheme picks one instead:
builder.Services.AddAuthentication()
.AddAnyCallerScheme(options =>
{
options.BearerScheme = OAuthServerServiceCollectionExtensions.ValidationScheme; // default: JWT if registered, else Identity bearer
options.ApiKeyScheme = "ApiKey"; // optional, with ApiKeyPrefix
options.ApiKeyPrefix = "ak_";
});
builder.Services.AddAuthorization(options => options.AddPolicy("any-caller", policy => policy
.AddAuthenticationSchemes(AnyCallerAuthenticationBuilderExtensions.SchemeName)
.RequireAuthenticatedUser()));
| Request | Handler |
|---|---|
Authorization credential starting with ApiKeyPrefix (as in Bearer ak_…) | ApiKeyScheme |
Any other Authorization header | BearerScheme |
No Authorization header | CookieScheme (the application cookie by default) |
A request with an invalid token and a valid cookie gets 401: the cookie is never read for it. The scheme is opt-in and does not change the default scheme. A token in the query string (QueryStringTokenPaths) has no Authorization header, so this scheme sends it to the cookie; keep those routes on the OAuth validation scheme.