skip to content

OpenID Connect Handler

AddOpenIdConnect signs users in at an external identity provider and keeps the result in a cookie. Interviewers probe the PKCE code flow, SaveTokens, claim mapping, sign-out and BFF setups for SPAs.

part ofASP.NET Coreread it →
on this pageshow

explore

questions

6

In ASP.NET Core, how does AddGoogle let users sign in with a Google account, and what does its handler do when Google redirects back?

level: juniorimportance: should knowfreq 35%

basics

~20 s

AddGoogle registers an OAuth-based remote handler: a challenge redirects to Google, and on /signin-google it exchanges the code, reads Google's userinfo endpoint, maps the JSON to claims and signs the principal into a cookie scheme.

open as a page

With ASP.NET Core's AddOpenIdConnect, why can a claim the identity provider issues be missing from HttpContext.User, and which options bring it back?

level: middleimportance: should knowfreq 42%

basics

~20 s

The OpenID Connect handler builds User from the validated ID token, deletes protocol claims via ClaimActions and reads userinfo only when GetClaimsFromUserInfoEndpoint is true. Even then a userinfo field becomes a claim only if a ClaimAction maps its JSON key.

open as a page

With ASP.NET Core's AddOpenIdConnect, why is a signed-out user often signed straight back in, and how do you sign out properly?

level: middleimportance: should knowfreq 38%

basics

~20 s

Signing out of the cookie scheme ends only the app's session; the identity provider's session survives, so the next challenge signs the user back in silently. Sign out of both the cookie and the OpenIdConnect schemes, which redirects to the provider's end-session endpoint.

open as a page

In ASP.NET Core 10, how do you put a single-page app behind a BFF that signs in with AddOpenIdConnect so the browser never holds an access token?

level: seniorimportance: should knowfreq 40%

basics

~20 s

The ASP.NET Core host is the OpenID Connect client: it signs in with AddOpenIdConnect, keeps the tokens in its encrypted cookie via SaveTokens and attaches the access token to downstream calls itself. The SPA only ever sends that cookie to same-origin endpoints.

open as a page

In ASP.NET Core 10's OpenIdConnectOptions, which defaults must change for the authorization code flow, and what do UsePkce and PushedAuthorizationBehavior then do?

level: seniorimportance: should knowfreq 45%

basics

~20 s

OpenIdConnectOptions.ResponseType defaults to id_token, so you set it to code and usually supply ClientSecret. PKCE then happens automatically, since UsePkce defaults to true, and since ASP.NET Core 9 the handler pushes the request via PAR whenever the provider advertises it.

open as a page