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) lets an application authenticate a user through an identity provider instead of storing the user’s credentials itself. Built on OAuth 2.0, it adds authentication, conventions, and discovery so the application can answer: “Which user sent this request?” section 25.1.3 section 25.7

From photo access to user identity

Imagine a photo-printing service requesting access to photos held by another service. With OAuth 2.0, the user signs in to the photo service, approves access, and the printing service receives an authorization code it can exchange for access. That grants permission to use the photos; it does not, by itself, tell the printing service who the user is. OpenID Connect follows a similar flow but adds an identity token describing the authentication event and a way 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 additional identity token and identity-details request are the important differences. section 25.1.3

In an ASP.NET Core API setup, keep the related pieces distinct:

  • An identity provider can centralize authentication and user management across applications and APIs. A third-party provider is worth considering before building one yourself; IdentityServer and OpenIddict implement OIDC but leave user management and its UI to you. section 25.7
  • APIs commonly receive bearer tokens formatted as JWTs. Validate a received JWT’s signature: its contents are readable by default, not encrypted. section 25.2 section 25.7
  • For a browser-based app, a Backend for Frontend can handle OIDC sign-in, keep bearer tokens out of the browser, and use a cookie for browser requests. The tradeoff is an additional backend service. section 25.2

For API testing, an OpenAPI security scheme can describe OIDC. With that scheme configured, Swagger UI’s Authorize action can redirect to the identity provider and retrieve a token instead of requiring a pasted bearer token. The shown Swashbuckle listing configures simpler bearer authentication, not OIDC itself. section 25.5

Check redirect destinations during sign-in. OIDC flows may need to redirect outside the application, so a local-URL-only check will not always work; preregister allowed redirect URLs and use only those destinations. section 29.4.1

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

How deep it goes
Explains OIDC through an OAuth flow and its added identity information, but stops short of a full protocol implementation.
Examples
Uses a photo-printing authorization flow, a Backend for Frontend pattern, and Swagger UI authentication to illustrate OIDC’s roles.
What it assumes
Introduces OAuth 2.0 before OIDC and does not require detailed protocol knowledge to add API authentication.
What you can do after
Evaluate/understand it as a way to delegate user authentication and distinguish identity information from OAuth 2.0 resource access.
How it connects
Connects OAuth 2.0, identity providers, bearer tokens, JWTs, Backend for Frontend, and OpenAPI security schemes.

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.