Repository navigation
Add Microsoft Entra ID service-to-service authentication and resilient HTTP clients - #205
Open
gentilegianluca wants to merge 2 commits into
Open
gentilegianluca wants to merge 2 commits into
gentilegianluca wants to merge 2 commits into
Conversation
added 2 commits
November 18, 2026 08:07
…va#204) Add a complete guide to the package README: quick start, how token validation works, Microsoft Entra ID setup for the target API and the client, credentials, migration from API keys, token verification, troubleshooting, requirements and limitations. Link the sample README to the new sections.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #203 and #204.
Summary
Adds the optional
SimpleAuthenticationTools.EntraIdpackage (src/SimpleAuthentication.EntraId, net8.0–net11.0), built on Microsoft.Identity.Web and Microsoft.Extensions.Http.Resilience, for service-to-service authentication with Microsoft Entra ID. It works next to the schemes and policies already registered by the application and doesn't change their defaults.What's included
Authentication (#203)
AddEntraIdJwtBearer: named JWT Bearer scheme (EntraIdby default, configurable) for a single tenant.TenantIdandClientIdmust be GUIDs; signature, issuer, audience and lifetime are always validated, even if the configuration tries to disable them; tokens of other tenants are rejected. The configuration is validated at startup.Authorization (#203)
RequireEntraIdApplicationRole(policy builder and endpoint convention): accepts only app-only tokens (idtyp = app, noscp) validated by the Entra ID scheme and containing one of the required application roles. Claims coming from other schemes can't satisfy the requirement.HTTP clients (#204)
AddEntraIdHttpClient: named client (usable as typed client, also with Refit) that acquires app-only tokens through Microsoft.Identity.Web, using the credentials and the token cache of the host. The token of the incoming request is never forwarded.BaseAddress(HTTP only on loopback, with explicit opt-in). Requests to other destinations andAuthorization/Hostheaders set by the caller are rejected; redirects and cookies are disabled; the token is redacted from logs.MarkAsIdempotent(). A single pipeline per client: handlers fromConfigureHttpClientDefaultsare removed, and adding or removing resilience handlers afterwards is reported when the client is created.Sample, tests and docs
samples/MinimalApis/EntraIdMicroservices: Orders API calling an Inventory API with its own identity.tests/SimpleAuthentication.EntraId.Tests: valid and invalid tokens (signature, audience, issuer, tenant, lifetime), application roles, coexistence with other schemes, HTTP client security and resilience, and an end-to-end call between two APIs with the real Microsoft.Identity.Web/MSAL stack against a simulated Entra ID authority..gitignore,version.jsonand apublish_entraid.ymlworkflow aligned with the existing packages.Testing
xunit.v3.mtp-off: with the .NET 10+ SDK,dotnet testdoesn't run Microsoft Testing Platform projects without an opt-in inglobal.json.idtypoptional claim, admin consent, client credentials), including the coexistence with API keys described in the README.Notes
publish_entraid.ymlneeds a NuGet trusted publishing policy for this workflow file before the first release.Microsoft.AspNetCore.Authentication.JwtBearerfor each target framework, likeSimpleAuthenticationTools.Abstractions: applications referencing an older patch directly getNU1605and need to update it.