Introduce new authentication provider Unauthenticated as the default#3075
Introduce new authentication provider Unauthenticated as the default#3075
Unauthenticated as the default#3075Conversation
Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
…and JSON schema Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Unauthenticated
There was a problem hiding this comment.
Pull request overview
Introduces a new Unauthenticated authentication provider intended to treat all requests as anonymous without requiring JWT configuration.
Changes:
- Added an
UnauthenticatedASP.NET Core auth handler/scheme and wired it intoStartupauth registration paths. - Updated CLI validation and config validation logic to allow
Unauthenticatedwithout JWT (with warnings for non-anonymous role permissions). - Extended schema and CLI tests/snapshots to include the new provider.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Service/Startup.cs | Registers the Unauthenticated auth scheme in both auth configuration paths. |
| src/Core/AuthenticationHelpers/UnauthenticatedAuthenticationHandler/UnauthenticatedAuthenticationHandler.cs | New auth handler that yields an anonymous principal. |
| src/Core/AuthenticationHelpers/UnauthenticatedAuthenticationHandler/UnauthenticatedAuthenticationDefaults.cs | Defines the scheme name constants for the new provider. |
| src/Core/AuthenticationHelpers/UnauthenticatedAuthenticationHandler/UnauthenticatedAuthenticationBuilderExtensions.cs | Adds an AuthenticationBuilder extension to register the new scheme. |
| src/Core/AuthenticationHelpers/SupportedAuthNProviders.cs | Adds Unauthenticated to the supported provider constants. |
| src/Config/ObjectModel/AuthenticationOptions.cs | Adds provider detection helper and updates JWT-required determination logic. |
| src/Cli/Utils.cs | Allows Unauthenticated to omit JWT audience/issuer and updates messaging. |
| src/Cli/ConfigGenerator.cs | Emits a warning when Unauthenticated is used with non-anonymous permissions. |
| src/Cli.Tests/ValidateConfigTests.cs | Adds unit tests for Unauthenticated provider helper methods. |
| src/Cli.Tests/Snapshots/InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders_47836da0dfbdc458.verified.txt | Updates snapshot for config generation using Unauthenticated. |
| src/Cli.Tests/InitTests.cs | Adds Unauthenticated as a test case for init/config generation. |
| schemas/dab.draft.schema.json | Adds Unauthenticated to the provider enum and documents it. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
|
@RubenCerna2079 you will need to help here and resolve the integration test errs for me. |
src/Core/AuthenticationHelpers/ClientRoleHeaderAuthenticationMiddleware.cs
Show resolved
Hide resolved
...ticationHelpers/UnauthenticatedAuthenticationHandler/UnauthenticatedAuthenticationHandler.cs
Outdated
Show resolved
Hide resolved
.../AuthenticationHelpers/UnauthenticatedAuthentication/UnauthenticatedAuthenticationHandler.cs
Show resolved
Hide resolved
| ClaimsIdentity identity = new(); | ||
| ClaimsPrincipal claimsPrincipal = new(identity); | ||
|
|
||
| AuthenticationTicket ticket = new(claimsPrincipal, UnauthenticatedAuthenticationDefaults.AUTHENTICATIONSCHEME); |
There was a problem hiding this comment.
Why do we need to add UnauthenticatedAuthenticationDefaults.AUTHENTICATIONSCHEME for the AuthenticationTicket if the in the ClaimsIdentity we don't use it since it is an unauthenticated user?
There was a problem hiding this comment.
The AuthenticationTicket requires a scheme name as part of the ASP.NET Core authentication infrastructure. While the ClaimsIdentity has no authenticationType (making it unauthenticated), the ticket still needs to identify which authentication handler processed the request. This follows the same pattern as SimulatorAuthenticationHandler.
RubenCerna2079
left a comment
There was a problem hiding this comment.
Missing tests for the following test methods
TestValidateAudienceAndIssuerForAuthenticationProviderinUtilTests.csTestBaseRouteIsConfigurableForSWAinEndToEndTests.csTestUpdateAuthenticationProviderHostSettingsinConfigureOptionsTests.cs
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
…ing, add tests Co-authored-by: RubenCerna2079 <32799214+RubenCerna2079@users.noreply.github.com>
Added in f0b25d0:
|
|
@copilot We need to update dab init in the CLI to default to this new provider when it is executed without an explicit flag. |
…ated Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Done in 17844ce. Changed the default authentication provider from
|
UnauthenticatedUnauthenticated as the default
Why make this change?
New authentication provider where all operations run as
anonymous. Useful when DAB is behind an app gateway or APIM where authentication is handled externally. This provider is now the default when executingdab initwithout an explicit--auth.providerflag.What is this change?
Core Implementation:
IsUnauthenticatedAuthenticationProvider()toAuthenticationOptions.csUnauthenticatedAuthenticationHandlerinUnauthenticatedAuthenticationfolder (follows Simulator pattern, returns unauthenticated ClaimsPrincipal)Startup.csto register the provider in bothConfigureAuthentication()andConfigureAuthenticationV2()ClientRoleHeaderAuthenticationMiddleware.ResolveConfiguredAuthNScheme()for proper scheme selection at request timeCLI & Validation:
AppServicetoUnauthenticatedfordab initUtils.ValidateAudienceAndIssuerForJwtProvider()to accept Unauthenticated without JWTConfigGenerator.IsConfigValid()when used with authenticated/custom roles (not an error)ConfigureOptions.csto reflect new defaultSchema:
Unauthenticatedtodab.draft.schema.jsonprovider enumKey behaviors:
dab initis executed without--auth.providerproductionmode (unlike Simulator)authenticated/custom role permissions (warning emitted)How was this tested?
ValidateUnauthenticatedProviderIdentificationtest inAuthenticationConfigValidatorUnitTests.csTestValidateAudienceAndIssuerForAuthenticationProvider(UtilsTests.cs)TestBaseRouteIsConfigurableForSWA(EndToEndTests.cs)TestUpdateAuthenticationProviderHostSettings(ConfigureOptionsTests.cs)Sample Request(s)
Config snippet:
{ "runtime": { "host": { "authentication": { "provider": "Unauthenticated" } } } }✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.