M365Con 2027 – free online conference · 11–22 Jan 2027 · 120 sessions m365con.net

Blog · Mirko Peters

What Is OpenID Connect? Microsoft Entra Sign-In Explained

By · · Updated

What is OpenID Connect? How OIDC adds sign-in on top of OAuth 2.0, ID token vs access token, the flows Microsoft Entra ID recommends, the discovery document and the mistakes app developers and admins should avoid.

What is OpenID Connect? It is the protocol behind almost every Sign in with Microsoft button. Microsoft Learn describes it as an extension of OAuth 2.0 that adds authentication: the app hands sign-in to Microsoft Entra ID and receives a signed ID token that says who the user is. The app never sees the password, and MFA and Conditional Access run on Microsoft's side.

Key points

  • OpenID Connect extends OAuth 2.0 so it can be used for authentication. OAuth 2.0 grants access, OIDC tells the app who signed in.
  • The ID token proves authentication and is meant for the client app. Microsoft says not to use it to call an API or for authorization.
  • Access tokens are for the API. Client apps should treat them as opaque strings and never parse or validate them.
  • For SPAs, web apps and desktop or mobile apps, Microsoft recommends the authorization code flow with PKCE. Microsoft recommends you do not use the implicit flow.
  • Signing keys roll over with no guaranteed schedule, so apps must read them from the discovery document instead of hardcoding them.
  • Use oid or sub, with tid, to identify users. Never use email or preferred_username for authorization decisions.

If you build apps, OIDC decides how you sign users in and which token you trust. If you run Entra, it decides what you check in an app registration. Most problems I see come from three things: the wrong token, the wrong flow, or hardcoded keys.

What is OpenID Connect, compared with OAuth 2.0?

OAuth 2.0 answers one question: what may this app do on the user's behalf? It produces an access token, a permission slip for an API. It says nothing reliable about who the user is.

OpenID Connect standardizes the missing part. The app adds the openid scope to its request, which shows up on the consent page as the Sign you in permission, and the identity provider returns an ID token next to, or instead of, the access token. OIDC also standardizes discovery, the profile and email scopes, a UserInfo endpoint and sign-out. Because Microsoft 365 and many third-party apps all hand sign-in to the same Entra ID session, the user signs in once. That is single sign-on.

ID token vs access token

In code reviews, mixing these two up is the OIDC bug I see most.

ID tokenAccess token
PurposeProof of authenticationProof of authorization
Read byThe client app that started the sign-inThe API named in the aud claim
Format for the clientJWT, the app reads its claimsOpaque string, the app never reads it
Default lifetime1 hourRandom, 60 to 90 minutes (up to 28 hours for CAE-capable clients; 2 hours for clients such as Teams and Microsoft 365 in tenants without Conditional Access)
Use to call an API?NoYes
Who validates itConfidential clients, with a libraryThe web API, never the client

An access token for Microsoft Graph is Graph's business. Your web app only needs the ID token to know who signed in. For lifetimes and the token lifetime policy, see Entra ID SAML vs OIDC and token lifetime policies.

What happens when a user clicks sign in

With the recommended authorization code flow, a sign-in looks like this:

  1. The app redirects the browser to the /oauth2/v2.0/authorize endpoint with its client ID, a registered redirect URI, scope=openid (plus any API scopes), a random state and nonce (MSAL and middleware set these for you) and a PKCE code_challenge.
  2. The user signs in on Microsoft's page. MFA and Conditional Access are evaluated there.
  3. Entra ID redirects back to the redirect URI with a short-lived authorization code and the state. The app first checks that state matches (protection against cross-site request forgery). For web apps, Microsoft recommends response_mode=form_post, which sends the response in the request body instead of the URL. Codes typically expire after about one minute.
  4. The app sends the code and the matching code_verifier to the token endpoint and receives the ID token, and an access token if it asked for API scopes. A refresh token comes back only when the app requests offline_access.
  5. The app validates the ID token and checks that its nonce matches the value it sent (protection against token replay).

PKCE is required for single-page apps and recommended for every other app type, public or confidential. Microsoft recommends you do not use the older implicit flow, and notes that its silent SSO breaks in browsers that block third-party cookies.

The discovery document and signing keys

Every Entra ID authority publishes its configuration at https://login.microsoftonline.com/{tenant}/v2.0/.well-known/openid-configuration. It lists the authorize, token and logout endpoints, the issuer and the jwks_uri with the public signing keys.

The {tenant} value is also your audience decision:

ValueWho can sign in
commonWork or school accounts and personal Microsoft accounts
organizationsWork or school accounts from any Entra tenant
consumersPersonal Microsoft accounts only
Tenant ID or domainUsers from that one tenant, including guests with personal Microsoft accounts

Key rollover is where hand-built integrations break. There is no set or guaranteed time between key rolls, and keys can be rolled immediately in an emergency. An app with a hardcoded key stops accepting sign-ins the day the key changes. Read keys from the jwks_uri and let the library cache and refresh them.

Mistakes I see in real apps

  • Using the ID token as an API key. It proves identity and grants nothing. Send access tokens to APIs, and have the API check aud, scopes and roles.
  • Identifying users by email. preferred_username is mutable and can't be used for authorization, and email isn't guaranteed to be correct. Use oid (same across apps in a tenant) or sub (unique per app), together with tid.
  • Skipping validation. Confidential clients should validate the signature, issuer, aud, timestamps and nonce. Public clients gain nothing from it, because a malicious user can tamper with the keys.
  • OIDC for a daemon. If no user is present, use the client credentials flow with application permissions and the .default scope. It returns an access token only. See our guide to service principals in Entra ID.
  • Forgetting local sign-out. The logout redirect alone is not enough. The app must also clear its own cookies or session.

My recommendation: don't write protocol code at all. Use MSAL for token acquisition, caching and refresh, and your web framework's Entra ID middleware for ID token validation and signing key refresh. ADAL has ended support, so any app still on it needs to move to MSAL.

What admins should check

Admins rarely touch the protocol, but they own the app registration. My review checklist:

  • Redirect URIs must match exactly and point only to hosts you control. SPAs need the spa platform type.
  • Under Authentication > Implicit grant and hybrid flows, leave the Access tokens and ID tokens (used for implicit and hybrid flows) checkboxes unticked unless the app documents a reason. Apps that use the hybrid flow (code id_token) need the ID tokens box, or sign-in fails with unsupported_response_type, so check before unticking it on a live app.
  • Supported account types should match the audience. A line-of-business app has no reason to accept personal Microsoft accounts.
  • Prefer managed identities or federated credentials, which need no secret. Otherwise, use certificates, not client secrets.

Older enterprise apps often speak only SAML, and that is fine. The SAML vs OIDC comparison linked above explains when each fits, and how SSO works in Microsoft 365 shows the user side.

Related

Sources

Follow the showApple PodcastsSpotify

FAQ

What is OpenID Connect in simple terms?

OpenID Connect (OIDC) is an identity layer on top of OAuth 2.0. When an app shows a Sign in with Microsoft button, it sends the user to Microsoft Entra ID, which checks the credentials and returns a signed ID token that tells the app who the user is. The app never sees the password.

What is the difference between an ID token and an access token?

The ID token is proof of authentication and is read by the client app that requested sign-in. The access token is proof of authorization and is meant for the API it was issued to, named in its aud claim. Microsoft says not to call APIs with ID tokens, and clients should treat access tokens as opaque.

Which OIDC flow should I use with Microsoft Entra ID?

For SPAs, server web apps and desktop or mobile apps, Microsoft recommends the authorization code flow with PKCE. PKCE is required for SPAs and recommended for all other app types. Microsoft recommends against the implicit flow, partly because its silent sign-in breaks in browsers that block third-party cookies.

Where is the OpenID Connect discovery document for Entra ID?

Append /.well-known/openid-configuration to the authority, for example https://login.microsoftonline.com/{tenant}/v2.0/.well-known/openid-configuration. It lists the authorize, token and logout endpoints, the issuer and the jwks_uri where the signing keys are published.

Should a background service use OpenID Connect?

No. OIDC signs in a user. A daemon or service with no user present should use the OAuth 2.0 client credentials flow with application permissions and the .default scope. That flow returns an access token only.

Entities in this article

Topics of this article:

OpenID Connect (OIDC) – Concept OAuth 2.0 – Concept Microsoft Entra ID – Identity and security tool by Microsoft Access token – Concept OAuth 2.0 authorization code flow – Narrower topic of Microsoft Entra Application registration – Narrower topic of Microsoft Entra ID

Related articles

More articles on OpenID Connect (OIDC):

RSS