liveBook · Manning

IdentityModel.OidcClient

As explained in .NET MAUI in Action

IdentityModel.OidcClient is a .NET client library for authenticating clients with OpenID Connect identity providers and processing authentication responses.

IdentityModel.OidcClient is a .NET client library that processes OpenID Connect authentication responses. In a .NET MAUI app, it works with WebAuthenticator so users sign in through an identity provider without giving the app their password. section 8.1.2

A typical authentication flow is assembled from these parts:

  • Configure OidcClientOptions with the authority, client ID, scopes, redirect URI, and an IBrowser implementation. section 8.1.2
  • Implement IdentityModel.OidcClient.Browser.IBrowser by calling WebAuthenticator.AuthenticateAsync with the identity provider URL and redirect URI. section 8.1.2 section 8.1.2
  • Call LoginAsync; OidcClient parses the returned authorization response and extracts the tokens needed by the authentication service. section 8.1.2
  • Register a custom URL scheme so the operating system can return the identity provider response to the app. section 8.1.2

MAUI authentication service

An AuthService creates OidcClientOptions with Authority, ClientId, Scope, RedirectUri, and a custom AuthBrowser, then calls new OidcClient(options).LoginAsync(new LoginRequest()). section 8.1.2

Figure 8.3 Step 1: Call the LoginAsync method of the OidcClient package. Step 2: The OidcClient package will call WebAuthenticator and display the login page on IdentityServer. Step 3: The user will log in to IdentityServer. Step 4: IdentityServer returns the result via WebAuthenticator. Step 5: The parsed result is returned to OidcClient. Step 6: OidcClient extracts the JWT from the result and returns it to the caller of the LoginAsync method.

Follow the six-step flow from LoginAsync through WebAuthenticator and the identity provider to the parsed result and extracted JWT. section 8.1.2

How .NET MAUI in Action covers it

How deep it goes
Explains configuration, browser integration, response parsing, token extraction, and platform redirect registration, but not provider internals.
Examples
Demonstrates MauiStockTake with AuthBrowser, AuthService, platform callback declarations, and a custom auth URL scheme.
What it assumes
Assumes basic .NET MAUI and C# familiarity while introducing browser-based OAuth 2.0 authentication from the application flow.
What you can do after
Build it from scratch by combining OidcClient with WebAuthenticator and platform-specific redirect configuration.
How it connects
Connects OpenID Connect, OAuth 2.0, WebAuthenticator, IdentityServer, authorization codes, access tokens, JWTs, and custom URL schemes.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET MAUI in Action. The section links point to the parts of the book it draws on.