liveBook · Manning

Openid connect

As explained in Building Distributed Applications that Work

OpenID Connect is an identity layer built on OAuth 2.0 that enables clients to verify user identity and obtain basic profile information.

OpenID Connect (OIDC) handles authentication: proving that a user is who they claim to be. In single sign-on (SSO), a shared identity provider (IdP) lets a user sign in once and access applications protected by that provider. OAuth addresses the separate question of authorization: whether the user may access a resource. section 8.1 section 8.6

For an online shop, signing in establishes who placed an order and helps prevent someone else from using a customer’s account. Keycloak acts as the IdP; the web application redirects unauthenticated users to it when they request protected pages. section 8.1 section 8.3

builder.Services.AddAuthentication(options =>
{
    options.DefaultScheme =
        CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme =
        OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(
    CookieAuthenticationDefaults.AuthenticationScheme)
.AddOpenIdConnect()
.ConfigureWebAppOpenIdConnect();

The UI registers cookie authentication as its default scheme and OIDC as its default challenge scheme. The cookie scheme reads the current identity; the OIDC challenge redirects an unauthenticated user to sign in. section 8.3

To enforce authentication in an ASP.NET Core UI:

  • Add Microsoft.AspNetCore.Authentication.OpenIdConnect and configure the IdP authority URL and backchannel HTTP client. section 8.3
  • Register authorization and place authentication and authorization middleware in the request pipeline. section 8.3
  • Mark pages requiring sign-in with the Authorize attribute. section 8.3

The signed-in state is retained temporarily, such as in a browser cookie. Access tokens expire and can be refreshed while the user remains active; eventually, the user must sign in again. This is the operational reason to configure both the sign-in challenge and the mechanism that reads an existing identity. section 8.1 section 8.3

How Building Distributed Applications that Work covers it

How deep it goes
Explains the sign-in flow at a high level and details ASP.NET Core UI configuration, without examining protocol internals.
Examples
Shows a Keycloak-backed online-shop UI with cookie and OIDC schemes, request middleware, and an Authorize-protected page.
What it assumes
Assumes an existing online-shop UI and Keycloak container while introducing the OIDC and OAuth distinction at a high level.
What you can do after
Apply it via Microsoft.AspNetCore.Authentication.OpenIdConnect to redirect unauthenticated ASP.NET Core UI users to an identity provider.
How it connects
Connects OIDC to single sign-on, identity providers, OAuth authorization, cookie authentication, and protected UI pages.

Also explained in

Compare how 13 books explain openid connect →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Distributed Applications that Work. The section links point to the parts of the book it draws on.