Upgrade to 4.0Changelog
Reference

People and agents

Tell a person calling directly apart from an AI agent or client with a delegated token, or an API key, and keep person-only actions for people.

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:

KindWho
personThe Identity application cookie, an Identity bearer token, or an AuthEndpoints JWT.
delegatedAn OAuth access token from AuthEndpoints.OpenIddict: a client acting for the person, or for a subject the person chose.
api_keyAn 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:

AreaRoutes
Password and profileGET and POST /manage/info, POST /manage/password, POST /resendConfirmationEmail
Two-factorGET and POST /manage/2fa
PasskeysPOST /passkeys/creationOptions, and GET, POST, PATCH /passkeys, DELETE /passkeys/{id}
ReAuthPOST /confirmIdentity, POST /confirmIdentity/passkeyOptions, POST /confirmIdentity/emailCode/send, GET /manage/authMethods
External sign-inGET /logins, DELETE /logins/{loginProvider}/{providerKey}, GET /link/{scheme}, GET /link/{scheme}/callback
SessionsGET /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()));
RequestHandler
Authorization credential starting with ApiKeyPrefix (as in Bearer ak_…)ApiKeyScheme
Any other Authorization headerBearerScheme
No Authorization headerCookieScheme (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.