An authorization code flow lets a client obtain tokens through a server-side exchange: the identity provider returns a code, which the application exchanges for tokens. In an ASP.NET Core UI app, OpenID Connect options request a code response; tokens can be saved for later use. section 8.3
Configuration can include client credentials and a callback path for the identity provider’s response. PKCE adds protection and is especially relevant to public clients; it is optional in the configuration described here. section 8.3
Listing 8.1 Configuring authentication in the UI app startup
public static void ConfigureWebAppOpenIdConnect(this AuthenticationBuilder authentication)
{
// Named options
authentication.Services
.AddOptions<OpenIdConnectOptions>(
OpenIdConnectDefaults.AuthenticationScheme)
.Configure<
IConfiguration,
IHttpClientFactory,
IHostEnvironment>(Configure);
// Unnamed options
authentication.Services.AddOptions<OpenIdConnectOptions>()
.Configure<
IConfiguration,
IHttpClientFactory,
IHostEnvironment>(Configure);
static void Configure(
OpenIdConnectOptions options,
IConfiguration configuration,
IHttpClientFactory httpClientFactory,
IHostEnvironment hostEnvironment)
{
var backchannelHttpClient =
httpClientFactory.CreateClient(
"OidcBackchannel");
options.Backchannel = backchannelHttpClient;
options.Authority =
backchannelHttpClient
.GetIdpAuthorityUri().ToString();
options.ClientId = "webapp";
options.ClientSecret =
Environment
.GetEnvironmentVariable(
"Identity__ClientSecret");
options.ResponseType =
OpenIdConnectResponseType.Code;
options.SaveTokens = true;
options.RequireHttpsMetadata =
!hostEnvironment.IsDevelopment();
options.MapInboundClaims = false;
}
}
Inspect the UI app’s OpenID Connect configuration, including how its options are registered and configured. section 8.3







