-
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
base: main
Are you sure you want to change the base?
Changes from all commits
4618b06
e4c09d2
f63c338
1a2f633
b6d0fd5
a441af8
e3fb034
00444b8
f0b25d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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: [] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| using System.Security.Claims; | ||
| using Azure.DataApiBuilder.Config.ObjectModel; | ||
| using Azure.DataApiBuilder.Core.AuthenticationHelpers.AuthenticationSimulator; | ||
| using Azure.DataApiBuilder.Core.AuthenticationHelpers.UnauthenticatedAuthentication; | ||
| using Azure.DataApiBuilder.Core.Authorization; | ||
| using Azure.DataApiBuilder.Core.Configurations; | ||
| using Azure.DataApiBuilder.Core.Models; | ||
|
|
@@ -192,6 +193,10 @@ private static string ResolveConfiguredAuthNScheme(string? configuredProviderNam | |
| { | ||
| return SimulatorAuthenticationDefaults.AUTHENTICATIONSCHEME; | ||
| } | ||
| else if (string.Equals(configuredProviderName, SupportedAuthNProviders.UNAUTHENTICATED, StringComparison.OrdinalIgnoreCase)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder if this need more testing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added test case |
||
| { | ||
| return UnauthenticatedAuthenticationDefaults.AUTHENTICATIONSCHEME; | ||
| } | ||
| else if (string.Equals(configuredProviderName, SupportedAuthNProviders.AZURE_AD, StringComparison.OrdinalIgnoreCase) || | ||
| string.Equals(configuredProviderName, SupportedAuthNProviders.ENTRA_ID, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
|
|
||
| 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.UnauthenticatedAuthentication; | ||
|
|
||
| /// <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; | ||
| } | ||
| } |
| 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.UnauthenticatedAuthentication; | ||
|
|
||
| /// <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"; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // 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.UnauthenticatedAuthentication; | ||
|
|
||
| /// <summary> | ||
| /// This class is used to best integrate with ASP.NET Core AuthenticationHandler base class. | ||
| /// Ref: https://github.com/dotnet/aspnetcore/blob/main/src/Security/Authentication/Core/src/AuthenticationHandler.cs | ||
| /// 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| AuthenticateResult success = AuthenticateResult.Success(ticket); | ||
| return Task.FromResult(success); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.