liveBook · Manning

Openid connect

As explained in ASP.NET Core in Action, 3e

OpenID Connect is an authentication protocol built on OAuth 2.0 that adds conventions, discovery, and user-identity authentication to delegated authorization flows.

OpenID Connect (OIDC) is an authentication protocol built on OAuth 2.0. It lets an application rely on an identity provider to authenticate users, rather than storing their credentials itself. OIDC adds conventions and discovery to OAuth 2.0, helping applications retrieve user identity information. section 25.1.3 section 25.7

OAuth 2.0 is concerned with delegated authorization: a user can let an application access a resource without giving it their credentials. OpenID Connect builds on that flow to answer a different question: which user authenticated? section 25.1.3

Signing in with an identity provider

A photo-printing service can redirect a user to Facebook, where the user signs in and consents to the requested access. In the OAuth 2.0 example, the service receives an authorization code and exchanges it using a shared secret. An OpenID Connect flow follows the same overall pattern but also provides an identity token describing the authentication event and an API call to retrieve identity details. section 25.1.3

Figure 25.6 Using OpenID Connect to authenticate with Facebook and retrieve identity information. The overall flow is the same as with Oauth 2.0, as shown in figure 25.5, but with an additional identity token describing the authentication event and API call to retrieve the identity details.
CH25_F06_Lock3

Compare the OpenID Connect flow with OAuth 2.0: the identity token and identity-details call add authentication information. section 25.1.3

In a Backend for Frontend (BFF) pattern, an ASP.NET Core backend handles OpenID Connect authentication, stores bearer tokens, and sets an authentication cookie. The browser sends the cookie to the backend, which uses a bearer token to call the API. This keeps bearer tokens out of the browser, but requires an additional backend service. section 25.2

Keep these practical details in mind:

  • Preregister allowed redirect URLs and redirect only to a registered URL. OpenID Connect flows may need external redirects, so a local-only redirect check is not always suitable. section 29.4.1
  • When receiving a JWT, always verify its signature. A JWT is not encrypted by default, so its contents can be read. section 25.7
  • An OpenAPI security scheme can describe OpenID Connect. In Swagger UI, choosing Authorize can then redirect users to the identity provider to sign in and retrieve a token. section 25.5
  • A third-party identity provider can reduce user-management responsibilities. If you need your own provider, IdentityServer or OpenIddict can implement OpenID Connect, but you still build the user-management and UI components. section 25.7

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains the protocol through a high-level flow and practical integration contexts, while leaving detailed protocol study for further reading.
Examples
Uses a photo-printing service and Facebook sign-in to contrast delegated photo access with identity authentication.
What it assumes
Introduces OAuth 2.0 before OpenID Connect and notes that detailed protocol knowledge is not essential to adding API authentication.
What you can do after
Evaluate and understand OpenID Connect’s role in authentication, its distinction from OAuth 2.0 authorization, and its use with a BFF.
How it connects
Connects OpenID Connect to OAuth 2.0, identity providers, JWTs, bearer authentication, and the Backend for Frontend pattern.

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 ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.