-
Notifications
You must be signed in to change notification settings - Fork 301
Introduce new authentication provider Unauthenticated
#3075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
7
commits into
main
Choose a base branch
from
copilot/add-unauthenticated-auth-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4618b06
Initial plan
Copilot e4c09d2
Updated plan with new requirements
Copilot f63c338
Add Unauthenticated authentication provider with CLI support, tests, …
Copilot 1a2f633
Fix typo in UnauthenticatedAuthenticationBuilderExtensions comment
Copilot b6d0fd5
Update src/Cli/Utils.cs
JerryNixon a441af8
Merge branch 'main' into copilot/add-unauthenticated-auth-provider
JerryNixon e3fb034
Address PR review comments: add Unauthenticated scheme mapping, use e…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
50 changes: 50 additions & 0 deletions
50
...CorrectConfigGenerationWithDifferentAuthenticationProviders_47836da0dfbdc458.verified.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| { | ||
| DataSource: { | ||
| DatabaseType: MSSQL, | ||
| Options: { | ||
| set-session-context: false | ||
| } | ||
| }, | ||
| Runtime: { | ||
| Rest: { | ||
| Enabled: true, | ||
| Path: /api, | ||
| RequestBodyStrict: true | ||
| }, | ||
| GraphQL: { | ||
| Enabled: true, | ||
| Path: /graphql, | ||
| AllowIntrospection: true | ||
| }, | ||
| Mcp: { | ||
| Enabled: true, | ||
| Path: /mcp, | ||
| DmlTools: { | ||
| AllToolsEnabled: true, | ||
| DescribeEntities: true, | ||
| CreateRecord: true, | ||
| ReadRecords: true, | ||
| UpdateRecord: true, | ||
| DeleteRecord: true, | ||
| ExecuteEntity: true, | ||
| UserProvidedAllTools: false, | ||
| UserProvidedDescribeEntities: false, | ||
| UserProvidedCreateRecord: false, | ||
| UserProvidedReadRecords: false, | ||
| UserProvidedUpdateRecord: false, | ||
| UserProvidedDeleteRecord: false, | ||
| UserProvidedExecuteEntity: false | ||
| } | ||
| }, | ||
| Host: { | ||
| Cors: { | ||
| AllowCredentials: false | ||
| }, | ||
| Authentication: { | ||
| Provider: Unauthenticated | ||
| }, | ||
| Mode: Production | ||
| } | ||
| }, | ||
| Entities: [] | ||
| } |
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
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
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
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
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
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
34 changes: 34 additions & 0 deletions
34
...rs/UnauthenticatedAuthenticationHandler/UnauthenticatedAuthenticationBuilderExtensions.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.AspNetCore.Authentication; | ||
|
|
||
| namespace Azure.DataApiBuilder.Core.AuthenticationHelpers.UnauthenticatedAuthenticationHandler; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods related to Unauthenticated authentication. | ||
| /// This class allows setting up Unauthenticated authentication in the startup class with | ||
| /// a single call to .AddAuthentication(scheme).AddUnauthenticatedAuthentication() | ||
| /// </summary> | ||
| public static class UnauthenticatedAuthenticationBuilderExtensions | ||
| { | ||
| /// <summary> | ||
| /// Add authentication with Unauthenticated provider. | ||
| /// </summary> | ||
| /// <param name="builder">Authentication builder.</param> | ||
| /// <returns>The builder, to chain commands.</returns> | ||
| public static AuthenticationBuilder AddUnauthenticatedAuthentication(this AuthenticationBuilder builder) | ||
| { | ||
| if (builder is null) | ||
| { | ||
| throw new System.ArgumentNullException(nameof(builder)); | ||
| } | ||
|
|
||
| builder.AddScheme<AuthenticationSchemeOptions, UnauthenticatedAuthenticationHandler>( | ||
| authenticationScheme: UnauthenticatedAuthenticationDefaults.AUTHENTICATIONSCHEME, | ||
| displayName: UnauthenticatedAuthenticationDefaults.AUTHENTICATIONSCHEME, | ||
| configureOptions: null); | ||
|
|
||
| return builder; | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
...tionHelpers/UnauthenticatedAuthenticationHandler/UnauthenticatedAuthenticationDefaults.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Azure.DataApiBuilder.Core.AuthenticationHelpers.UnauthenticatedAuthenticationHandler; | ||
|
|
||
| /// <summary> | ||
| /// Default values related to UnauthenticatedAuthentication handler. | ||
| /// </summary> | ||
| public static class UnauthenticatedAuthenticationDefaults | ||
| { | ||
| /// <summary> | ||
| /// The default value used for UnauthenticatedAuthenticationOptions.AuthenticationScheme. | ||
| /// </summary> | ||
| public const string AUTHENTICATIONSCHEME = "UnauthenticatedAuthentication"; | ||
| } |
49 changes: 49 additions & 0 deletions
49
...ationHelpers/UnauthenticatedAuthenticationHandler/UnauthenticatedAuthenticationHandler.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Security.Claims; | ||
| using System.Text.Encodings.Web; | ||
| using Microsoft.AspNetCore.Authentication; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Extensions.Options; | ||
|
|
||
| namespace Azure.DataApiBuilder.Core.AuthenticationHelpers.UnauthenticatedAuthenticationHandler; | ||
|
|
||
| /// <summary> | ||
| /// This class is used to best integrate with ASP.NET Core AuthenticationHandler base class. | ||
| /// When "Unauthenticated" is configured, this handler authenticates the user as anonymous, | ||
| /// without reading any HTTP authentication headers. | ||
| /// </summary> | ||
| public class UnauthenticatedAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions> | ||
| { | ||
| /// <summary> | ||
| /// Constructor for the UnauthenticatedAuthenticationHandler. | ||
| /// Note the parameters are required by the base class. | ||
| /// </summary> | ||
| /// <param name="options">Authentication options.</param> | ||
| /// <param name="logger">Logger factory.</param> | ||
| /// <param name="encoder">URL encoder.</param> | ||
| public UnauthenticatedAuthenticationHandler( | ||
| IOptionsMonitor<AuthenticationSchemeOptions> options, | ||
| ILoggerFactory logger, | ||
| UrlEncoder encoder) | ||
| : base(options, logger, encoder) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns an unauthenticated ClaimsPrincipal for all requests. | ||
| /// The ClaimsPrincipal has no identity and no claims, representing an anonymous user. | ||
| /// </summary> | ||
| /// <returns>An authentication result to ASP.NET Core library authentication mechanisms</returns> | ||
| protected override Task<AuthenticateResult> HandleAuthenticateAsync() | ||
| { | ||
| // ClaimsIdentity without authenticationType means the user is not authenticated (anonymous) | ||
| ClaimsIdentity identity = new(); | ||
| ClaimsPrincipal claimsPrincipal = new(identity); | ||
|
|
||
| AuthenticationTicket ticket = new(claimsPrincipal, UnauthenticatedAuthenticationDefaults.AUTHENTICATIONSCHEME); | ||
| AuthenticateResult success = AuthenticateResult.Success(ticket); | ||
| return Task.FromResult(success); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.