InsightsIAM and AI agents

OAuth, OpenID Connect and AI agents: who may do what, for whom.

As long as a person clicks, sign-in through your identity provider is solved. Once an AI agent acts for that person, every step needs its own token, and the log must show who acted for whom. Both flows in two pictures, checked against the IETF RFCs, the MCP specification, Keycloak and Microsoft Entra.

30 minutes · remote · Ludwig Oswald, Munich

For
Architecture, IT security, platform teams, product owners
As of
26 Oct 2026
Sources
IETF, OpenID Foundation, MCP, Keycloak, Microsoft, OWASP, NIST
By
Ludwig Oswald, Cloud & Solution Architect
01 In short

The answer in three points.

  1. OAuth governs what an application may do on behalf of a user. OpenID Connect tells it who signed in. The current practice is the authorization code flow with Proof Key for Code Exchange (PKCE); for business applications in the browser, a backend of their own holds the tokens and the browser only a session cookie.
  2. AI agents add three rules: an identity of its own for each agent, every token for exactly one audience, and no service passes on a token it received but obtains its own, for example through token exchange. The Model Context Protocol (MCP) specification requires tokens issued for its servers and forbids passing tokens on.
  3. Keycloak and Entra ID provide much of this, some of it only as a preview, and they handle delegation differently. Check what your version can do before you plan.
02 Diagram

Sign-in and access: authorization code with PKCE and OpenID Connect.

From left to right the browser, your application with a backend of its own, the authorization server and the API. Solid arrows run server to server, dashed ones through the browser. The boxes show what each side checks.

Authorization code flow with PKCE and OpenID Connect
Authorization code flow with PKCE and OpenID ConnectFour parties side by side: the browser, your application with a backend of its own as a confidential client, the authorization server as OpenID provider, for example Keycloak or Entra ID, and the API as resource server. The flow in ten steps: 1. The user opens the application. 2. The backend creates state, nonce and code_verifier. 3. It redirects the browser to the authorization server with code_challenge using S256, state, nonce and the scopes openid and that of the API. 4. The user signs in, with a second factor and consent. 5. The authorization server redirects back with code, state and iss, and the browser hands them to the backend. 6. The backend checks state and iss. 7. At the token endpoint it exchanges the code together with the code_verifier and authenticates as a confidential client; the server checks that its SHA-256 value matches the code_challenge. 8. Back come the ID token, an access token for the API and a refresh token. 9. The backend validates the ID token: signature through the published keys, issuer, audience, expiry and nonce, and sets a session cookie. 10. It calls the API with the access token; the API checks signature, issuer, audience, expiry and scope. OAuth governs what the application may do, OpenID Connect who signed in. With a backend of its own, the tokens never reach the browser.Browseruser agentClient appbackend (BFF), confidentialAuthorization serverOpenID provider · Keycloak · Entra IDAPIresource server1open the app2create state · nonce · code_verifier3302 redirect/authorize: code_challenge (S256) · state · nonce · scope: openid + API scope4sign-in · MFA · consent5redirect back: code · state · isscode · state · iss6check state and iss7/token: code · code_verifier · client authSHA-256(code_verifier) = code_challenge?8id_token · access_token (aud = API) · refresh_token9validate id_token: signature (JWKS) · iss · aud · exp · nonce → session cookie10request with access tokencheck signature · iss · aud · exp · scopeserver to server (back channel)through the browser (front channel)OAuth: what the app may do (access token) · OIDC: who signed in (ID token)With a backend for the frontend, tokens never reach the browser; the browser holds only a session cookie.
Simplified: not every parameter is shown, and refresh, sign-out and error cases are left out. Servers that support RFC 9207, such as Keycloak, send the iss parameter. Instead of a backend, an application in the browser can hold the tokens itself; for business applications, sensitive applications and personal data, RFC 10017 strongly recommends the backend.

An AI agent acting for a user.

The authorization server on top, below it the chain from the user through the agent and the MCP server to the business API. Each step receives a token for exactly one audience; below each box is what gets checked there.

An AI agent acting for a user
An AI agent acting for a userOn top the authorization server, for example Keycloak or Entra ID, which issues short-lived tokens for one audience each. Below it the chain: user, AI agent as MCP client with an identity of its own, MCP server as tool and resource server, business API such as CRM, ERP or tickets. 1. The user gives the agent a task. 2. The agent calls the tool without a token and receives a 401 response, here pointing to the server metadata. 3. Through the flow of the first picture, authorization code with PKCE, the agent obtains a token with resource set to the MCP server. It contains sub set to the user, aud set to the MCP server, client_id set to the agent and may_act set to the MCP server. 4. The MCP server exchanges this token through token exchange for a new one with sub set to the user, aud set to the API and act set to the MCP server. 5. It calls the API. 6. The API checks audience and scope and logs the user and the acting service; together with the log of the MCP server this shows who acted for whom. Checks below the boxes: at the user, consent before tool calls, revocable; at the agent, its own registration, an accountable sponsor, least privilege; at the MCP server, accept only tokens for itself, never pass tokens on, log user and agent, and request extended permissions for risky actions (step-up). At the bottom, what the platforms provide today: Keycloak with standard token exchange since 26.2, delegation with the act claim as a preview in 26.8, MCP authorization supported for revision 2025-03-26 and experimental for later ones. Entra ID with on-behalf-of through the JWT bearer grant for delegated permissions, and Agent ID: a blueprint holds the credentials, a sponsor is required, and in the token the user is the subject and the agent appears in azp. As an MCP authorization server, Entra ID lists no PKCE methods in its metadata (checked 26 Oct 2026), so MCP clients must stop.Authorization serverissues short-lived tokens for one audience each · Keycloak · Entra IDUsersigned in (flow 1)AI agentMCP client · own identityMCP servertool · resource serverBusiness APICRM, ERP, tickets1task2call tool401 · resource_metadata3code flow + PKCE (as flow 1)resource = MCP serversub = useraud = MCP serverclient_id = agentmay_act = MCP server4token exchangesubject = received tokenactor = MCP serversub = useraud = APIact = MCP server5callown client per agentaccountable sponsorleast scopesaccept only aud = itselfnever pass tokens onlog user and agentstep-up for risky actionscheck aud · scopelog user and act6who did it, for whomconsent before tool callsrevocableKEYCLOAKstandard token exchange since 26.2 · delegation with act claim: preview in 26.8 · MCP auth: 2025-03-26 supported, newer experimentalENTRA IDOn-Behalf-Of (JWT bearer, delegated scopes) · Agent ID: blueprint holds credentials, sponsor required, token: sub = user, agent in azpas MCP authorization server: no code_challenge_methods_supported in its metadata (checked 26 Oct 2026), so MCP clients must stopStandards: RFC 8707 resource indicators · RFC 8693 token exchange (act claim) · RFC 9728 protected resource metadata · MCP authorization
Schematic. Instead of the MCP server, the agent itself can exchange a token for the business API. The rules stay the same: one audience per token, no passing on, the chain in the logs.
03 Building blocks

Six building blocks, and what they are for.

Authorization code with PKCE

The application sends the user to the authorization server and receives a code that it exchanges for tokens. PKCE ties the exchange to the start: only whoever knows the secret code_verifier can redeem the code. The method S256 is stated explicitly; without it, “plain” applies.

  • RFC 7636
  • RFC 9700
  • S256

IETF, RFC 7636, read 25 Oct 2026 · IETF, RFC 9700, read 25 Oct 2026

Validate the ID token

The ID token tells the application who signed in. It checks issuer, audience, expiry and the nonce it created beforehand; the nonce binds the ID token to this sign-in and exposes injected codes and replayed tokens. It checks the signature through the published keys (JWKS). In the code flow, the specification allows relying on the TLS connection instead.

  • OIDC Core 3.1.3.7
  • nonce
  • JWKS

OpenID Foundation, OpenID Connect Core 1.0, read 25 Oct 2026

Backend for frontend

A backend of the web application is the OAuth client. It holds access and refresh tokens, the browser only a cookie with Secure and HttpOnly. RFC 10017 strongly recommends this for business applications, sensitive applications and personal data: a script that gets into the page finds no token there. It can still trigger requests through the backend; that remains a risk of every web application.

  • RFC 10017
  • BFF
  • confidential client

IETF, RFC 10017, read 25 Oct 2026

One token, one audience

With the resource parameter the client states which service it needs a token for, and the authorization server should restrict the token to that audience (aud). Each service accepts only tokens issued for it. A stolen token then opens only one service.

  • RFC 8707
  • aud
  • RFC 9068

IETF, RFC 8707, read 25 Oct 2026 · IETF, RFC 9068, read 26 Oct 2026 · IETF, RFC 9700, read 25 Oct 2026

Token exchange instead of passing on

When a service needs another one, it can exchange the token it received at the authorization server for a new one for the next audience. With delegation, the user stays the subject of the new token, and the acting service appears in the act claim. That keeps visible who acted for whom.

  • RFC 8693
  • act
  • may_act

IETF, RFC 8693, read 25 Oct 2026

An identity for each agent

An agent signs in with an identity of its own, not with a person’s account and not with a shared key. It gets only the permissions its task needs, a human confirms risky actions, and someone is accountable for it. Entra ID calls this role the sponsor, held by a person or a group, and requires it at creation.

  • Agent ID
  • Sponsor
  • least privilege

Microsoft, Agent identities, read 25 Oct 2026 · Microsoft, Owners, sponsors and managers, read 25 Oct 2026 · OWASP, Top 10 for Agentic Applications, read 25 Oct 2026

04 Frameworks

Standards and platforms.

What the implementation follows, as of 26 Oct 2026.

01

RFC 9700, security best practice for OAuth 2.0

Best current practice since January 2025: PKCE required for public clients and recommended for confidential ones, stop using the implicit grant, never use the password grant, match redirect URIs exactly, sender-constrain refresh tokens of public clients or rotate them on every use.

IETF, RFC 9700, read 25 Oct 2026

02

OAuth 2.1 and OpenID Connect

OAuth 2.1 consolidates this practice but is still a draft, most recently version 16 of 3 Sep 2026. OpenID Connect Core 1.0 with errata set 2 defines how to validate the ID token. RFC 9207 adds the iss parameter so that a client does not confuse authorization servers.

IETF, draft-ietf-oauth-v2-1, read 25 Oct 2026 · OpenID Foundation, OpenID Connect Core 1.0, read 25 Oct 2026 · IETF, RFC 9207, read 25 Oct 2026

03

MCP specification 2026-07-28

Authorization is optional; HTTP implementations should follow it. Then: servers publish their metadata under RFC 9728, clients send resource under RFC 8707, servers check the audience and never pass a token on. PKCE is required, with S256 where technically possible; if an authorization server lists no PKCE methods in its metadata, clients stop.

MCP, Authorization, read 25 Oct 2026 · MCP, Security Best Practices, read 25 Oct 2026 · IETF, RFC 9728, read 25 Oct 2026

04

Keycloak 26.8

Standard token exchange under RFC 8693 has been supported since version 26.2. Delegation with the act claim is a preview in 26.8. As an authorization server for MCP, revision 2025-03-26 is supported; later revisions and resource indicators are experimental.

Keycloak, Token exchange, read 25 Oct 2026 · Keycloak, MCP authorization server, read 25 Oct 2026 · Keycloak, 26.8.1 released, read 25 Oct 2026

05

Microsoft Entra ID

On-behalf-of exchanges a user token through the JWT bearer grant, not under RFC 8693. Entra Agent ID has been generally available since April 2026, and the security features for agents require Microsoft Agent 365. A blueprint holds the credentials, and a sponsor is required. When an agent acts for a user, the token names the user as subject and the agent in azp; there is no act claim. Entra ID lists no PKCE methods in its OpenID metadata, so MCP clients following revision 2026-07-28 must stop.

Microsoft, On-behalf-of flow, read 25 Oct 2026 · Microsoft, What’s new in Microsoft Entra, read 26 Oct 2026 · Microsoft, What is Microsoft Entra Agent ID?, read 26 Oct 2026 · Microsoft, Token claims for agents, read 26 Oct 2026 · Microsoft Entra, OpenID metadata (measured), read 26 Oct 2026 · MCP, Security considerations, read 26 Oct 2026

06

OWASP and NIST

The OWASP Top 10 for Agentic Applications of December 2025 list identity and privilege abuse as ASI03. In February 2026, the NIST NCCoE published a concept paper on identity and authorization of software and AI agents; the first use case is DevSecOps.

OWASP, Top 10 for Agentic Applications, read 25 Oct 2026 · NIST NCCoE, Software and AI Agent Identity, read 25 Oct 2026 · NIST, Comments on the concept paper, read 26 Oct 2026

As of 26 Oct 2026. Preview and experimental features may change before the stable release.

05 What we do not claim

Four common assumptions, checked.

01

“OAuth is a sign-in protocol.”

OAuth governs what an application may do. Who signed in is what OpenID Connect adds with the ID token. The access token is meant for the API, not for the application.

OpenID Foundation, OpenID Connect Core 1.0, read 25 Oct 2026 · IETF, RFC 9068, read 25 Oct 2026

02

“OAuth 2.1 is the current standard.”

It is still an IETF draft. The practice in force today is RFC 9700; OAuth 2.1 largely adopts it.

IETF, RFC 9700, read 25 Oct 2026 · IETF, draft-ietf-oauth-v2-1, read 25 Oct 2026

03

“The agent simply takes the user’s token along.”

The MCP specification forbids passing tokens on to other services and requires a server to accept only tokens issued for it. Every step receives its own token.

MCP, Authorization, read 25 Oct 2026 · MCP, Security Best Practices, read 25 Oct 2026

04

“The act claim shows the whole chain.”

The outer act names the current actor. Earlier actors appear only if the authorization server nests them inside, and under RFC 8693 they are informational only, so they are no basis for access decisions. Who acted for whom therefore also belongs in the log of every service.

IETF, RFC 8693, section 4.1, read 25 Oct 2026

06 Questions

Questions about OAuth, OpenID Connect and AI agents.

Do we need a new identity and access management (IAM) for AI agents?

Usually not. The identity provider you already have will generally do, with clear rules: a registration of its own for each agent, tokens with one audience, token exchange between services and logs that show the whole chain. What is new is managing agents as identities of their own with a responsible person.

Microsoft, Agent identities, read 25 Oct 2026 · IETF, RFC 8693, read 25 Oct 2026

Keycloak or Entra ID for agents?

Usually decided by where your users and applications already are. Entra ID brings a ready model for agents with Agent ID. Keycloak runs in your own environment, and you model agents with dedicated clients and policies. With either, check in advance which features you need are stable in your version and whether your MCP clients work with the server.

Microsoft, What is Microsoft Entra Agent ID?, read 26 Oct 2026 · Keycloak, MCP authorization server, read 25 Oct 2026

Where do we start?

With a list of applications and agents: which flow, where the tokens live, for which audiences, with which permissions. First goes what RFC 9700 no longer provides for, implicit flow and password grant, and for business applications under RFC 10017 also tokens in the browser. Then the agents: their own registration, the audience in every token, token exchange and a log that shows who acted for whom.

IETF, RFC 9700, read 25 Oct 2026 · IETF, RFC 10017, read 26 Oct 2026 · MCP, Authorization, read 25 Oct 2026

Read on: AI agents · RAG architecture in production · SSDLC and security gates · Software & Cloud

Terms in this article 20
Access token
A token that shows an API what an application may do on behalf of a user or in its own name. It is meant for the API, not for the application.
act claim
A field in a token naming the party, such as a service, that currently acts for the subject. Earlier actors can be nested inside and are informational only.
Agent identity
An AI agent’s own identity at the identity provider, with its own permissions and a responsible person, separate from the user’s account. Microsoft Entra manages it as an agent identity in the product Agent ID.
Audienceaud
The field in a token that names the recipient it was issued for. The client can name the recipient with the resource parameter; otherwise the authorization server sets it, for example from the scope. A service accepts only tokens that name itself.
Authorization code flow
The OAuth flow in which the application receives a one-time code after sign-in and exchanges it for tokens over a direct connection to the authorization server.
Authorization server
The service that signs users in and issues tokens, for example Keycloak or Entra ID. In OpenID Connect it is called the OpenID provider.
BFFBackend for frontend
A backend of a web application that holds the tokens as the OAuth client. The browser only has a session cookie.
ID token
A signed OpenID Connect token that tells the application who signed in with which provider. The application checks signature, issuer, audience, expiry and nonce.
JWKSJSON Web Key Set
Published public keys, for example of an authorization server, which applications and APIs use to verify the signature of a token.
MCPModel Context Protocol
An open protocol through which AI applications use tools and data sources. An MCP server provides, for example, a calendar, tickets or a database.
MFAMulti-factor authentication
Sign-in with at least one second factor besides the password, such as an app or a security key.
Nonce
A one-time value the application sends at sign-in and expects back in the ID token. It binds the token to the sign-in and exposes injected codes and replayed tokens.
OAuth 2.0
A framework through which an application accesses an API on behalf of a user without knowing the user’s password. The security practice in force is RFC 9700; OAuth 2.1 is still a draft.
OIDCOpenID Connect
A standard for signing in through an identity provider such as Entra ID or Okta. The application receives a signed token and verifies it.
On-behalf-ofOBO
The Microsoft Entra ID method by which an API exchanges a user token for one for a further API. It uses the JWT bearer grant, not RFC 8693.
PKCEProof Key for Code Exchange
Protection for the authorization code flow: the application sends the hash of a secret at the start and presents the secret when redeeming the code. An intercepted code is useless to an attacker without the secret.
Protected resource metadata
A description of an API at /.well-known/oauth-protected-resource, including the responsible authorization servers and the scopes. MCP servers with authorization must provide it.
Scope
The extent of a permission an application requests, for example reading calendars. The user consents, and the API checks the scope in the token.
SSOSingle sign-on
One sign-in with the company account for several applications. Whoever leaves the company loses access in one place.
Token exchange
A service exchanges a token it received at the authorization server for a new one for the next recipient instead of passing it on. With delegation, the user stays the subject, and the acting service appears in the act claim.

All terms in the glossary →

07 Contact

Want your agents to have only the access their task needs?

In a first call we look at how sign-in and tokens work today and what your agents still need.

I use your details only to answer your enquiry. More in the privacy policy.