diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index b550e8c..322f075 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -35,7 +35,7 @@ jobs:
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v1.9.0
with:
- dotnet-version: 8.x.x
+ dotnet-version: 9.x.x
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
diff --git a/LICENSE b/LICENSE
index cf26481..7414cdd 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2024 Mihir Dilip
+Copyright (c) 2025 Mihir Dilip
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index a0698f4..18efedd 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ Easy to use and very light weight Microsoft style API Key Authentication Impleme
## .NET (Core) Frameworks Supported
.NET Framework 4.6.1 and/or NetStandard 2.0 onwards
-Multi targeted: net8.0; net7.0; net6.0; net5.0; netcoreapp3.1; netcoreapp3.0; netstandard2.0; net461
+Multi targeted: net9.0; net8.0; net7.0; net6.0; net5.0; netcoreapp3.1; netcoreapp3.0; netstandard2.0; net461
@@ -384,6 +384,7 @@ public void ConfigureServices(IServiceCollection services)
## Release Notes
| Version | Notes |
|---------|-------|
+|9.0.0 |
- net9.0 support added
- Sample project for net9.0 added
- Readme updated
- Nullable reference types enabled
- Language version set to latest
- Implicit usings enabled
- AOT support added
|
|8.0.1 | - Added support to have ApiKey in request route identified by route pattern key from netcoreapp3.0 onwards [#41](https://github.com/mihirdilip/aspnetcore-authentication-apikey/issues/41)
- Readme updated
|
|8.0.0 | - net8.0 support added
- Sample project for net8.0 added
- ApiKeySamplesClient.http file added for testing sample projects
- Readme updated
|
|7.0.0 | - net7.0 support added
- Information log on handler is changed to Debug log when API Key is not found on the request
- Added package validations
- Sample project for net7.0 added
- Readme updated
- Readme added to package
|
diff --git a/samples/SampleWebApi.Shared/Services/ApiKeyProvider.cs b/samples/SampleWebApi.Shared/Services/ApiKeyProvider.cs
index bc4f06d..21df338 100644
--- a/samples/SampleWebApi.Shared/Services/ApiKeyProvider.cs
+++ b/samples/SampleWebApi.Shared/Services/ApiKeyProvider.cs
@@ -16,7 +16,7 @@ public ApiKeyProvider(ILogger logger, IApiKeyRepository apiKeyR
_apiKeyRepository = apiKeyRepository;
}
- public async Task ProvideAsync(string key)
+ public async Task ProvideAsync(string key)
{
try
{
diff --git a/samples/SampleWebApi_2_0/SampleWebApi_2_0.csproj b/samples/SampleWebApi_2_0/SampleWebApi_2_0.csproj
index 8ac49e3..91e3ec9 100644
--- a/samples/SampleWebApi_2_0/SampleWebApi_2_0.csproj
+++ b/samples/SampleWebApi_2_0/SampleWebApi_2_0.csproj
@@ -4,6 +4,8 @@
netcoreapp2.0
false
false
+ latest
+ enable
diff --git a/samples/SampleWebApi_2_2/SampleWebApi_2_2.csproj b/samples/SampleWebApi_2_2/SampleWebApi_2_2.csproj
index 0dafbeb..70329b3 100644
--- a/samples/SampleWebApi_2_2/SampleWebApi_2_2.csproj
+++ b/samples/SampleWebApi_2_2/SampleWebApi_2_2.csproj
@@ -5,6 +5,8 @@
InProcess
false
false
+ latest
+ enable
diff --git a/samples/SampleWebApi_3_1/SampleWebApi_3_1.csproj b/samples/SampleWebApi_3_1/SampleWebApi_3_1.csproj
index 5fc5145..4334354 100644
--- a/samples/SampleWebApi_3_1/SampleWebApi_3_1.csproj
+++ b/samples/SampleWebApi_3_1/SampleWebApi_3_1.csproj
@@ -2,6 +2,7 @@
netcoreapp3.1
+ enable
false
diff --git a/samples/SampleWebApi_5_0/SampleWebApi_5_0.csproj b/samples/SampleWebApi_5_0/SampleWebApi_5_0.csproj
index 451e988..0aabe64 100644
--- a/samples/SampleWebApi_5_0/SampleWebApi_5_0.csproj
+++ b/samples/SampleWebApi_5_0/SampleWebApi_5_0.csproj
@@ -2,6 +2,7 @@
net5.0
+ enable
false
diff --git a/samples/SampleWebApi_7_0/SampleWebApi_7_0.csproj b/samples/SampleWebApi_7_0/SampleWebApi_7_0.csproj
index 77f760b..f1992e9 100644
--- a/samples/SampleWebApi_7_0/SampleWebApi_7_0.csproj
+++ b/samples/SampleWebApi_7_0/SampleWebApi_7_0.csproj
@@ -4,6 +4,7 @@
net7.0
enable
enable
+ false
diff --git a/samples/SampleWebApi_9_0/Controllers/ValuesController.cs b/samples/SampleWebApi_9_0/Controllers/ValuesController.cs
new file mode 100644
index 0000000..cd46903
--- /dev/null
+++ b/samples/SampleWebApi_9_0/Controllers/ValuesController.cs
@@ -0,0 +1,36 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using System.Text;
+
+namespace SampleWebApi_9_0.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class ValuesController : ControllerBase
+ {
+ // GET api/values
+ [AllowAnonymous]
+ [HttpGet]
+ public ActionResult> Get()
+ {
+ return new string[] { "value1", "value2" };
+ }
+
+ [HttpGet("claims")]
+ public ActionResult Claims()
+ {
+ var sb = new StringBuilder();
+ foreach (var claim in User.Claims)
+ {
+ sb.AppendLine($"{claim.Type}: {claim.Value}");
+ }
+ return sb.ToString();
+ }
+
+ [HttpGet("forbid")]
+ public new IActionResult Forbid()
+ {
+ return base.Forbid();
+ }
+ }
+}
diff --git a/samples/SampleWebApi_9_0/Program.cs b/samples/SampleWebApi_9_0/Program.cs
new file mode 100644
index 0000000..56f9ce1
--- /dev/null
+++ b/samples/SampleWebApi_9_0/Program.cs
@@ -0,0 +1,163 @@
+using AspNetCore.Authentication.ApiKey;
+using Microsoft.AspNetCore.Authorization;
+using SampleWebApi.Repositories;
+using SampleWebApi.Services;
+
+var builder = WebApplication.CreateBuilder(args);
+
+// Add User repository to the dependency container.
+builder.Services.AddTransient();
+
+// Add the ApiKey scheme authentication here..
+// It requires Realm to be set in the options if SuppressWWWAuthenticateHeader is not set.
+// If an implementation of IApiKeyProvider interface is registered in the dependency register as well as OnValidateKey delegete on options.Events is also set then this delegate will be used instead of an implementation of IApiKeyProvider.
+builder.Services.AddAuthentication(ApiKeyDefaults.AuthenticationScheme)
+
+ // The below AddApiKeyInHeaderOrQueryParams without type parameter will require OnValidateKey delegete on options.Events to be set unless an implementation of IApiKeyProvider interface is registered in the dependency register.
+ // Please note if OnValidateKey delegete on options.Events is also set then this delegate will be used instead of ApiKeyProvider.*
+ //.AddApiKeyInHeaderOrQueryParams(options =>
+
+ // The below AddApiKeyInHeaderOrQueryParams with type parameter will add the ApiKeyProvider to the dependency register.
+ // Please note if OnValidateKey delegete on options.Events is also set then this delegate will be used instead of ApiKeyProvider.
+ .AddApiKeyInHeaderOrQueryParams(options =>
+ {
+ options.Realm = "Sample Web API";
+ options.KeyName = "X-API-KEY";
+
+ //// Optional option to suppress the browser login dialog for ajax calls.
+ //options.SuppressWWWAuthenticateHeader = true;
+
+ //// Optional option to ignore extra check of ApiKey string after it is validated.
+ //options.ForLegacyIgnoreExtraValidatedApiKeyCheck = true;
+
+ //// Optional option to ignore authentication if AllowAnonumous metadata/filter attribute is added to an endpoint.
+ //options.IgnoreAuthenticationIfAllowAnonymous = true;
+
+ //// Optional events to override the ApiKey original logic with custom logic.
+ //// Only use this if you know what you are doing at your own risk. Any of the events can be assigned.
+ options.Events = new ApiKeyEvents
+ {
+
+ //// A delegate assigned to this property will be invoked just before validating the api key.
+ //OnValidateKey = async (context) =>
+ //{
+ // // custom code to handle the api key, create principal and call Success method on context.
+ // var apiKeyRepository = context.HttpContext.RequestServices.GetRequiredService();
+ // var apiKey = await apiKeyRepository.GetApiKeyAsync(context.ApiKey);
+ // var isValid = apiKey != null && apiKey.Key.Equals(context.ApiKey, StringComparison.OrdinalIgnoreCase);
+ // if (isValid)
+ // {
+ // context.Response.Headers.Add("ValidationCustomHeader", "From OnValidateKey");
+ // var claims = new[]
+ // {
+ // new Claim(ClaimTypes.NameIdentifier, apiKey.OwnerName, ClaimValueTypes.String, context.Options.ClaimsIssuer),
+ // new Claim(ClaimTypes.Name, apiKey.OwnerName, ClaimValueTypes.String, context.Options.ClaimsIssuer),
+ // new Claim("CustomClaimType", "Custom Claim Value - from OnValidateKey")
+ // };
+ // context.Principal = new ClaimsPrincipal(new ClaimsIdentity(claims, context.Scheme.Name));
+ // context.Success();
+ // }
+ // else
+ // {
+ // context.NoResult();
+ // }
+ //},
+
+ //// A delegate assigned to this property will be invoked just before validating the api key.
+ //// NOTE: Same as above delegate but slightly different implementation which will give same result.
+ //OnValidateKey = async (context) =>
+ //{
+ // // custom code to handle the api key, create principal and call Success method on context.
+ // var apiKeyRepository = context.HttpContext.RequestServices.GetRequiredService();
+ // var apiKey = await apiKeyRepository.GetApiKeyAsync(context.ApiKey);
+ // var isValid = apiKey != null && apiKey.Key.Equals(context.ApiKey, StringComparison.OrdinalIgnoreCase);
+ // if (isValid)
+ // {
+ // context.Response.Headers.Add("ValidationCustomHeader", "From OnValidateKey");
+ // var claims = new[]
+ // {
+ // new Claim("CustomClaimType", "Custom Claim Value - from OnValidateKey")
+ // };
+ // context.ValidationSucceeded(apiKey.OwnerName, claims); // claims are optional
+ // }
+ // else
+ // {
+ // context.ValidationFailed();
+ // }
+ //},
+
+ //// A delegate assigned to this property will be invoked before a challenge is sent back to the caller when handling unauthorized response.
+ //OnHandleChallenge = async (context) =>
+ //{
+ // // custom code to handle authentication challenge unauthorized response.
+ // context.Response.StatusCode = StatusCodes.Status401Unauthorized;
+ // context.Response.Headers.Add("ChallengeCustomHeader", "From OnHandleChallenge");
+ // await context.Response.WriteAsync("{\"CustomBody\":\"From OnHandleChallenge\"}");
+ // context.Handled(); // important! do not forget to call this method at the end.
+ //},
+
+ //// A delegate assigned to this property will be invoked if Authorization fails and results in a Forbidden response.
+ //OnHandleForbidden = async (context) =>
+ //{
+ // // custom code to handle forbidden response.
+ // context.Response.StatusCode = StatusCodes.Status403Forbidden;
+ // context.Response.Headers.Add("ForbidCustomHeader", "From OnHandleForbidden");
+ // await context.Response.WriteAsync("{\"CustomBody\":\"From OnHandleForbidden\"}");
+ // context.Handled(); // important! do not forget to call this method at the end.
+ //},
+
+ //// A delegate assigned to this property will be invoked when the authentication succeeds. It will not be called if OnValidateKey delegate is assigned.
+ //// It can be used for adding claims, headers, etc to the response.
+ //OnAuthenticationSucceeded = (context) =>
+ //{
+ // //custom code to add extra bits to the success response.
+ // context.Response.Headers.Add("SuccessCustomHeader", "From OnAuthenticationSucceeded");
+ // var customClaims = new List
+ // {
+ // new Claim("CustomClaimType", "Custom Claim Value - from OnAuthenticationSucceeded")
+ // };
+ // context.AddClaims(customClaims);
+ // //or can add like this - context.Principal.AddIdentity(new ClaimsIdentity(customClaims));
+ // return Task.CompletedTask;
+ //},
+
+ //// A delegate assigned to this property will be invoked when the authentication fails.
+ //OnAuthenticationFailed = (context) =>
+ //{
+ // // custom code to handle failed authentication.
+ // context.Fail("Failed to authenticate");
+ // return Task.CompletedTask;
+ //}
+
+ };
+ });
+
+builder.Services.AddControllers(options =>
+{
+ // ALWAYS USE HTTPS (SSL) protocol in production when using ApiKey authentication.
+ //options.Filters.Add();
+
+}); //.AddXmlSerializerFormatters() // To enable XML along with JSON;
+
+// All the requests will need to be authorized.
+// Alternatively, add [Authorize] attribute to Controller or Action Method where necessary.
+builder.Services.AddAuthorizationBuilder()
+ .AddFallbackPolicy(
+ "FallbackPolicy",
+ new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()
+ );
+
+var app = builder.Build();
+
+// Configure the HTTP request pipeline.
+
+app.UseHttpsRedirection();
+
+app.UseAuthentication(); // NOTE: DEFAULT TEMPLATE DOES NOT HAVE THIS, THIS LINE IS REQUIRED AND HAS TO BE ADDED!!!
+
+app.UseAuthorization();
+
+app.MapControllers();
+
+app.Run();
+
diff --git a/samples/SampleWebApi_9_0/Properties/launchSettings.json b/samples/SampleWebApi_9_0/Properties/launchSettings.json
new file mode 100644
index 0000000..18b1392
--- /dev/null
+++ b/samples/SampleWebApi_9_0/Properties/launchSettings.json
@@ -0,0 +1,41 @@
+{
+ "$schema": "http://json.schemastore.org/launchsettings.json",
+ "iisSettings": {
+ "windowsAuthentication": false,
+ "anonymousAuthentication": true,
+ "iisExpress": {
+ "applicationUrl": "http://localhost:3920",
+ "sslPort": 44304
+ }
+ },
+ "profiles": {
+ "http": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "api/values",
+ "applicationUrl": "http://localhost:5000",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "https": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "api/values",
+ "applicationUrl": "https://localhost:5001;http://localhost:5000",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "IIS Express": {
+ "commandName": "IISExpress",
+ "launchBrowser": true,
+ "launchUrl": "api/values",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ }
+ }
+}
diff --git a/samples/SampleWebApi_9_0/SampleWebApi_9_0.csproj b/samples/SampleWebApi_9_0/SampleWebApi_9_0.csproj
new file mode 100644
index 0000000..b08ff33
--- /dev/null
+++ b/samples/SampleWebApi_9_0/SampleWebApi_9_0.csproj
@@ -0,0 +1,19 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/SampleWebApi_9_0/appsettings.Development.json b/samples/SampleWebApi_9_0/appsettings.Development.json
new file mode 100644
index 0000000..0c208ae
--- /dev/null
+++ b/samples/SampleWebApi_9_0/appsettings.Development.json
@@ -0,0 +1,8 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ }
+}
diff --git a/samples/SampleWebApi_9_0/appsettings.json b/samples/SampleWebApi_9_0/appsettings.json
new file mode 100644
index 0000000..10f68b8
--- /dev/null
+++ b/samples/SampleWebApi_9_0/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "AllowedHosts": "*"
+}
diff --git a/samples/SampleWebApi_AOT/Program.cs b/samples/SampleWebApi_AOT/Program.cs
new file mode 100644
index 0000000..55892f6
--- /dev/null
+++ b/samples/SampleWebApi_AOT/Program.cs
@@ -0,0 +1,187 @@
+using AspNetCore.Authentication.ApiKey;
+using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Authorization;
+using SampleWebApi.Repositories;
+using SampleWebApi.Services;
+using System.Text;
+using System.Text.Json.Serialization;
+
+var builder = WebApplication.CreateSlimBuilder(args);
+builder.WebHost.UseKestrelHttpsConfiguration();
+
+// Add User repository to the dependency container.
+builder.Services.AddTransient();
+
+// Add the ApiKey scheme authentication here..
+// It requires Realm to be set in the options if SuppressWWWAuthenticateHeader is not set.
+// If an implementation of IApiKeyProvider interface is registered in the dependency register as well as OnValidateKey delegete on options.Events is also set then this delegate will be used instead of an implementation of IApiKeyProvider.
+builder.Services.AddAuthentication(ApiKeyDefaults.AuthenticationScheme)
+
+ // The below AddApiKeyInHeaderOrQueryParams without type parameter will require OnValidateKey delegete on options.Events to be set unless an implementation of IApiKeyProvider interface is registered in the dependency register.
+ // Please note if OnValidateKey delegete on options.Events is also set then this delegate will be used instead of ApiKeyProvider.*
+ //.AddApiKeyInHeaderOrQueryParams(options =>
+
+ // The below AddApiKeyInHeaderOrQueryParams with type parameter will add the ApiKeyProvider to the dependency register.
+ // Please note if OnValidateKey delegete on options.Events is also set then this delegate will be used instead of ApiKeyProvider.
+ .AddApiKeyInHeaderOrQueryParams(options =>
+ {
+ options.Realm = "Sample Web API";
+ options.KeyName = "X-API-KEY";
+
+ //// Optional option to suppress the browser login dialog for ajax calls.
+ //options.SuppressWWWAuthenticateHeader = true;
+
+ //// Optional option to ignore extra check of ApiKey string after it is validated.
+ //options.ForLegacyIgnoreExtraValidatedApiKeyCheck = true;
+
+ //// Optional option to ignore authentication if AllowAnonumous metadata/filter attribute is added to an endpoint.
+ //options.IgnoreAuthenticationIfAllowAnonymous = true;
+
+ //// Optional events to override the ApiKey original logic with custom logic.
+ //// Only use this if you know what you are doing at your own risk. Any of the events can be assigned.
+ options.Events = new ApiKeyEvents
+ {
+
+ //// A delegate assigned to this property will be invoked just before validating the api key.
+ //OnValidateKey = async (context) =>
+ //{
+ // // custom code to handle the api key, create principal and call Success method on context.
+ // var apiKeyRepository = context.HttpContext.RequestServices.GetRequiredService();
+ // var apiKey = await apiKeyRepository.GetApiKeyAsync(context.ApiKey);
+ // var isValid = apiKey != null && apiKey.Key.Equals(context.ApiKey, StringComparison.OrdinalIgnoreCase);
+ // if (isValid)
+ // {
+ // context.Response.Headers.Add("ValidationCustomHeader", "From OnValidateKey");
+ // var claims = new[]
+ // {
+ // new Claim(ClaimTypes.NameIdentifier, apiKey.OwnerName, ClaimValueTypes.String, context.Options.ClaimsIssuer),
+ // new Claim(ClaimTypes.Name, apiKey.OwnerName, ClaimValueTypes.String, context.Options.ClaimsIssuer),
+ // new Claim("CustomClaimType", "Custom Claim Value - from OnValidateKey")
+ // };
+ // context.Principal = new ClaimsPrincipal(new ClaimsIdentity(claims, context.Scheme.Name));
+ // context.Success();
+ // }
+ // else
+ // {
+ // context.NoResult();
+ // }
+ //},
+
+ //// A delegate assigned to this property will be invoked just before validating the api key.
+ //// NOTE: Same as above delegate but slightly different implementation which will give same result.
+ //OnValidateKey = async (context) =>
+ //{
+ // // custom code to handle the api key, create principal and call Success method on context.
+ // var apiKeyRepository = context.HttpContext.RequestServices.GetRequiredService();
+ // var apiKey = await apiKeyRepository.GetApiKeyAsync(context.ApiKey);
+ // var isValid = apiKey != null && apiKey.Key.Equals(context.ApiKey, StringComparison.OrdinalIgnoreCase);
+ // if (isValid)
+ // {
+ // context.Response.Headers.Add("ValidationCustomHeader", "From OnValidateKey");
+ // var claims = new[]
+ // {
+ // new Claim("CustomClaimType", "Custom Claim Value - from OnValidateKey")
+ // };
+ // context.ValidationSucceeded(apiKey.OwnerName, claims); // claims are optional
+ // }
+ // else
+ // {
+ // context.ValidationFailed();
+ // }
+ //},
+
+ //// A delegate assigned to this property will be invoked before a challenge is sent back to the caller when handling unauthorized response.
+ //OnHandleChallenge = async (context) =>
+ //{
+ // // custom code to handle authentication challenge unauthorized response.
+ // context.Response.StatusCode = StatusCodes.Status401Unauthorized;
+ // context.Response.Headers.Add("ChallengeCustomHeader", "From OnHandleChallenge");
+ // await context.Response.WriteAsync("{\"CustomBody\":\"From OnHandleChallenge\"}");
+ // context.Handled(); // important! do not forget to call this method at the end.
+ //},
+
+ //// A delegate assigned to this property will be invoked if Authorization fails and results in a Forbidden response.
+ //OnHandleForbidden = async (context) =>
+ //{
+ // // custom code to handle forbidden response.
+ // context.Response.StatusCode = StatusCodes.Status403Forbidden;
+ // context.Response.Headers.Add("ForbidCustomHeader", "From OnHandleForbidden");
+ // await context.Response.WriteAsync("{\"CustomBody\":\"From OnHandleForbidden\"}");
+ // context.Handled(); // important! do not forget to call this method at the end.
+ //},
+
+ //// A delegate assigned to this property will be invoked when the authentication succeeds. It will not be called if OnValidateKey delegate is assigned.
+ //// It can be used for adding claims, headers, etc to the response.
+ //OnAuthenticationSucceeded = (context) =>
+ //{
+ // //custom code to add extra bits to the success response.
+ // context.Response.Headers.Add("SuccessCustomHeader", "From OnAuthenticationSucceeded");
+ // var customClaims = new List
+ // {
+ // new Claim("CustomClaimType", "Custom Claim Value - from OnAuthenticationSucceeded")
+ // };
+ // context.AddClaims(customClaims);
+ // //or can add like this - context.Principal.AddIdentity(new ClaimsIdentity(customClaims));
+ // return Task.CompletedTask;
+ //},
+
+ //// A delegate assigned to this property will be invoked when the authentication fails.
+ //OnAuthenticationFailed = (context) =>
+ //{
+ // // custom code to handle failed authentication.
+ // context.Fail("Failed to authenticate");
+ // return Task.CompletedTask;
+ //}
+
+ };
+ });
+
+// All the requests will need to be authorized.
+// Alternatively, add [Authorize] attribute to Controller or Action Method where necessary.
+builder.Services.AddAuthorizationBuilder()
+ .AddFallbackPolicy(
+ "FallbackPolicy",
+ new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()
+ );
+
+builder.Services.ConfigureHttpJsonOptions(options =>
+{
+ options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
+});
+
+var app = builder.Build();
+
+app.UseHttpsRedirection();
+
+app.UseAuthentication(); // NOTE: DEFAULT TEMPLATE DOES NOT HAVE THIS, THIS LINE IS REQUIRED AND HAS TO BE ADDED!!!
+
+app.UseAuthorization();
+
+var valuesApi = app.MapGroup("/api/values")
+ .RequireAuthorization();
+valuesApi.MapGet("/", () => new[] { "value1", "value2" })
+ .AllowAnonymous();
+valuesApi.MapGet("/claims", async (context) =>
+{
+ var sb = new StringBuilder();
+ foreach (var claim in context.User.Claims)
+ {
+ sb.AppendLine($"{claim.Type}: {claim.Value}");
+ }
+ context.Response.StatusCode = 200;
+ await context.Response.WriteAsync(sb.ToString());
+});
+valuesApi.MapGet("/forbid", async (context) =>
+{
+ await context.ForbidAsync();
+});
+
+app.Run();
+
+
+[JsonSerializable(typeof(string))]
+[JsonSerializable(typeof(string[]))]
+internal partial class AppJsonSerializerContext : JsonSerializerContext
+{
+
+}
\ No newline at end of file
diff --git a/samples/SampleWebApi_AOT/Properties/launchSettings.json b/samples/SampleWebApi_AOT/Properties/launchSettings.json
new file mode 100644
index 0000000..b26d850
--- /dev/null
+++ b/samples/SampleWebApi_AOT/Properties/launchSettings.json
@@ -0,0 +1,17 @@
+{
+ "$schema": "https://json.schemastore.org/launchsettings.json",
+ "profiles": {
+ "https": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "api/values",
+ "applicationUrl": "https://localhost:44304;http://localhost:3920",
+ "sslPort": 44304,
+ "useSSL": true,
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ }
+ }
+}
diff --git a/samples/SampleWebApi_AOT/SampleWebApi_AOT.csproj b/samples/SampleWebApi_AOT/SampleWebApi_AOT.csproj
new file mode 100644
index 0000000..1695af2
--- /dev/null
+++ b/samples/SampleWebApi_AOT/SampleWebApi_AOT.csproj
@@ -0,0 +1,21 @@
+
+
+
+ net9.0
+ enable
+ enable
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/SampleWebApi_AOT/appsettings.Development.json b/samples/SampleWebApi_AOT/appsettings.Development.json
new file mode 100644
index 0000000..0c208ae
--- /dev/null
+++ b/samples/SampleWebApi_AOT/appsettings.Development.json
@@ -0,0 +1,8 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ }
+}
diff --git a/samples/SampleWebApi_AOT/appsettings.json b/samples/SampleWebApi_AOT/appsettings.json
new file mode 100644
index 0000000..10f68b8
--- /dev/null
+++ b/samples/SampleWebApi_AOT/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "AllowedHosts": "*"
+}
diff --git a/src/AspNetCore.Authentication.ApiKey.sln b/src/AspNetCore.Authentication.ApiKey.sln
index 1ed81b5..5d1c2be 100644
--- a/src/AspNetCore.Authentication.ApiKey.sln
+++ b/src/AspNetCore.Authentication.ApiKey.sln
@@ -38,6 +38,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApi_7_0", "..\samp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApi_8_0", "..\samples\SampleWebApi_8_0\SampleWebApi_8_0.csproj", "{5F0968BA-062C-4C7F-B40C-B1E1641FCEF6}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApi_9_0", "..\samples\SampleWebApi_9_0\SampleWebApi_9_0.csproj", "{B1469317-6D92-45B4-9AE1-FC9B70D26B9B}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApi_AOT", "..\samples\SampleWebApi_AOT\SampleWebApi_AOT.csproj", "{AB621904-C1BF-43F8-AFC3-B5097443F8C4}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -80,6 +84,14 @@ Global
{5F0968BA-062C-4C7F-B40C-B1E1641FCEF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F0968BA-062C-4C7F-B40C-B1E1641FCEF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F0968BA-062C-4C7F-B40C-B1E1641FCEF6}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B1469317-6D92-45B4-9AE1-FC9B70D26B9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B1469317-6D92-45B4-9AE1-FC9B70D26B9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B1469317-6D92-45B4-9AE1-FC9B70D26B9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B1469317-6D92-45B4-9AE1-FC9B70D26B9B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AB621904-C1BF-43F8-AFC3-B5097443F8C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AB621904-C1BF-43F8-AFC3-B5097443F8C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AB621904-C1BF-43F8-AFC3-B5097443F8C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AB621904-C1BF-43F8-AFC3-B5097443F8C4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -94,6 +106,8 @@ Global
{D1056CEF-550A-4EEB-B12B-1093DD3125AC} = {3C777BBB-7464-43FB-A046-EA465791AB0C}
{BE461B80-9EB5-41AF-9C18-39740A7BD057} = {3C777BBB-7464-43FB-A046-EA465791AB0C}
{5F0968BA-062C-4C7F-B40C-B1E1641FCEF6} = {3C777BBB-7464-43FB-A046-EA465791AB0C}
+ {B1469317-6D92-45B4-9AE1-FC9B70D26B9B} = {3C777BBB-7464-43FB-A046-EA465791AB0C}
+ {AB621904-C1BF-43F8-AFC3-B5097443F8C4} = {3C777BBB-7464-43FB-A046-EA465791AB0C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {70815049-1680-480A-BF5A-00536D6C9C20}
@@ -101,6 +115,8 @@ Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{1e1e202b-efb2-40fd-8271-659f36084916}*SharedItemsImports = 5
..\samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{5f0968ba-062c-4c7f-b40c-b1e1641fcef6}*SharedItemsImports = 5
+ ..\samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{ab621904-c1bf-43f8-afc3-b5097443f8c4}*SharedItemsImports = 5
+ ..\samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{b1469317-6d92-45b4-9ae1-fc9b70d26b9b}*SharedItemsImports = 5
..\samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{be461b80-9eb5-41af-9c18-39740a7bd057}*SharedItemsImports = 5
..\samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{cabeeeae-3974-4cc4-97f1-18c8d2188daf}*SharedItemsImports = 5
..\samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{d1056cef-550a-4eeb-b12b-1093dd3125ac}*SharedItemsImports = 5
diff --git a/src/AspNetCore.Authentication.ApiKey/ApiKeyExtensions.cs b/src/AspNetCore.Authentication.ApiKey/ApiKeyExtensions.cs
index b7269e0..937ddae 100644
--- a/src/AspNetCore.Authentication.ApiKey/ApiKeyExtensions.cs
+++ b/src/AspNetCore.Authentication.ApiKey/ApiKeyExtensions.cs
@@ -5,7 +5,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
-using System;
+using System.Diagnostics.CodeAnalysis;
namespace AspNetCore.Authentication.ApiKey
{
@@ -42,7 +42,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder
///
/// The configure options.
/// The instance of
- public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, Action configureOptions)
+ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, Action? configureOptions)
=> builder.AddApiKeyInHeader(ApiKeyDefaults.AuthenticationScheme, configureOptions);
///
@@ -53,7 +53,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder
/// The authentication scheme.
/// The configure options.
/// The instance of
- public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions)
+ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions)
=> builder.AddApiKeyInHeader(authenticationScheme, displayName: null, configureOptions: configureOptions);
///
@@ -65,7 +65,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder
/// The display name.
/// The configure options.
/// The instance of
- public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions)
+ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions)
=> builder.AddApiKey(authenticationScheme, displayName, configureOptions);
@@ -79,8 +79,13 @@ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder
///
///
/// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInHeader<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInHeader(ApiKeyDefaults.AuthenticationScheme);
+#else
public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInHeader(ApiKeyDefaults.AuthenticationScheme);
+#endif
///
/// Adds API Key - In Header authentication scheme to the project. It takes a implementation of as type parameter.
@@ -90,8 +95,13 @@ public static AuthenticationBuilder AddApiKeyInHeader(this Auth
///
/// The authentication scheme.
/// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInHeader<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInHeader(authenticationScheme, configureOptions: null);
+#else
public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, string authenticationScheme) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInHeader(authenticationScheme, configureOptions: null);
+#endif
///
/// Adds API Key - In Header authentication scheme to the project. It takes a implementation of as type parameter.
@@ -101,8 +111,13 @@ public static AuthenticationBuilder AddApiKeyInHeader(this Auth
///
/// The .
/// The instance of
- public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInHeader<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInHeader(ApiKeyDefaults.AuthenticationScheme, configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInHeader(ApiKeyDefaults.AuthenticationScheme, configureOptions);
+#endif
///
/// Adds API Key - In Header authentication scheme to the project. It takes a implementation of as type parameter.
@@ -113,8 +128,13 @@ public static AuthenticationBuilder AddApiKeyInHeader(this Auth
/// The authentication scheme.
/// The .
/// The instance of
- public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInHeader<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInHeader(authenticationScheme, displayName: null, configureOptions: configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInHeader(authenticationScheme, displayName: null, configureOptions: configureOptions);
+#endif
///
/// Adds API Key - In Header authentication scheme to the project. It takes a implementation of as type parameter.
@@ -126,10 +146,15 @@ public static AuthenticationBuilder AddApiKeyInHeader(this Auth
/// The display name.
/// The .
/// The instance of
- public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInHeader<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKey(authenticationScheme, displayName, configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKey(authenticationScheme, displayName, configureOptions);
+#endif
- #endregion // API Key - In Header
+#endregion // API Key - In Header
#region API Key - In Authorization Header
@@ -159,7 +184,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this Authenti
///
/// The configure options.
/// The instance of
- public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, Action configureOptions)
+ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, Action? configureOptions)
=> builder.AddApiKeyInAuthorizationHeader(ApiKeyDefaults.AuthenticationScheme, configureOptions);
///
@@ -170,7 +195,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this Authenti
/// The authentication scheme.
/// The configure options.
/// The instance of
- public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions)
+ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions)
=> builder.AddApiKeyInAuthorizationHeader(authenticationScheme, displayName: null, configureOptions: configureOptions);
///
@@ -182,7 +207,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this Authenti
/// The display name.
/// The configure options.
/// The instance of
- public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions)
+ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions)
=> builder.AddApiKey(authenticationScheme, displayName, configureOptions);
@@ -196,8 +221,13 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this Authenti
///
///
/// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInAuthorizationHeader(ApiKeyDefaults.AuthenticationScheme);
+#else
public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInAuthorizationHeader(ApiKeyDefaults.AuthenticationScheme);
+#endif
///
/// Adds API Key - In Authorization Header authentication scheme to the project. It takes a implementation of as type parameter.
@@ -207,8 +237,13 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader
/// The authentication scheme.
/// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInAuthorizationHeader(authenticationScheme, configureOptions: null);
+#else
public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, string authenticationScheme) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInAuthorizationHeader(authenticationScheme, configureOptions: null);
+#endif
///
/// Adds API Key - In Authorization Header authentication scheme to the project. It takes a implementation of as type parameter.
@@ -218,8 +253,13 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader
/// The .
/// The instance of
- public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInAuthorizationHeader(ApiKeyDefaults.AuthenticationScheme, configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInAuthorizationHeader(ApiKeyDefaults.AuthenticationScheme, configureOptions);
+#endif
///
/// Adds API Key - In Authorization Header authentication scheme to the project. It takes a implementation of as type parameter.
@@ -230,8 +270,13 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeaderThe authentication scheme.
/// The .
/// The instance of
- public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInAuthorizationHeader(authenticationScheme, displayName: null, configureOptions: configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInAuthorizationHeader(authenticationScheme, displayName: null, configureOptions: configureOptions);
+#endif
///
/// Adds API Key - In Authorization Header authentication scheme to the project. It takes a implementation of as type parameter.
@@ -243,8 +288,13 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeaderThe display name.
/// The .
/// The instance of
- public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKey(authenticationScheme, displayName, configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKey(authenticationScheme, displayName, configureOptions);
+#endif
#endregion // API Key - In Authorization Header
@@ -276,7 +326,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBu
///
/// The configure options.
/// The instance of
- public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, Action configureOptions)
+ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, Action? configureOptions)
=> builder.AddApiKeyInQueryParams(ApiKeyDefaults.AuthenticationScheme, configureOptions);
///
@@ -287,7 +337,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBu
/// The authentication scheme.
/// The configure options.
/// The instance of
- public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions)
+ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions)
=> builder.AddApiKeyInQueryParams(authenticationScheme, displayName: null, configureOptions: configureOptions);
///
@@ -299,7 +349,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBu
/// The display name.
/// The configure options.
/// The instance of
- public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions)
+ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions)
=> builder.AddApiKey(authenticationScheme, displayName, configureOptions);
@@ -313,8 +363,13 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBu
///
///
/// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInQueryParams<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInQueryParams(ApiKeyDefaults.AuthenticationScheme);
+#else
public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInQueryParams(ApiKeyDefaults.AuthenticationScheme);
+#endif
///
/// Adds API Key - In Query Parameters authentication scheme to the project. It takes a implementation of as type parameter.
@@ -324,8 +379,13 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this
///
/// The authentication scheme.
/// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInQueryParams<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInQueryParams(authenticationScheme, configureOptions: null);
+#else
public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, string authenticationScheme) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInQueryParams(authenticationScheme, configureOptions: null);
+#endif
///
/// Adds API Key - In Query Parameters authentication scheme to the project. It takes a implementation of as type parameter.
@@ -335,8 +395,13 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this
///
/// The .
/// The instance of
- public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInQueryParams<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInQueryParams(ApiKeyDefaults.AuthenticationScheme, configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInQueryParams(ApiKeyDefaults.AuthenticationScheme, configureOptions);
+#endif
///
/// Adds API Key - In Query Parameters authentication scheme to the project. It takes a implementation of as type parameter.
@@ -347,8 +412,13 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this
/// The authentication scheme.
/// The .
/// The instance of
- public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInQueryParams<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInQueryParams(authenticationScheme, displayName: null, configureOptions: configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInQueryParams(authenticationScheme, displayName: null, configureOptions: configureOptions);
+#endif
///
/// Adds API Key - In Query Parameters authentication scheme to the project. It takes a implementation of as type parameter.
@@ -360,20 +430,25 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this
/// The display name.
/// The .
/// The instance of
- public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInQueryParams<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKey(authenticationScheme, displayName, configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKey(authenticationScheme, displayName, configureOptions);
+#endif
- #endregion // API Key - In Query Parameters
+ #endregion // API Key - In Query Parameters
- #region API Key - In Header Or Query Parameters
+ #region API Key - In Header Or Query Parameters
- ///
- /// Adds API Key - In Header Or Query Parameters authentication scheme to the project.
- /// delegate must be set on the .
- ///
- ///
- /// The instance of
- public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder)
+ ///
+ /// Adds API Key - In Header Or Query Parameters authentication scheme to the project.
+ /// delegate must be set on the .
+ ///
+ ///
+ /// The instance of
+ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder)
=> builder.AddApiKeyInHeaderOrQueryParams(ApiKeyDefaults.AuthenticationScheme);
///
@@ -393,7 +468,7 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this Authenti
///
/// The configure options.
/// The instance of
- public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, Action configureOptions)
+ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, Action? configureOptions)
=> builder.AddApiKeyInHeaderOrQueryParams(ApiKeyDefaults.AuthenticationScheme, configureOptions);
///
@@ -404,7 +479,7 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this Authenti
/// The authentication scheme.
/// The configure options.
/// The instance of
- public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions)
+ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions)
=> builder.AddApiKeyInHeaderOrQueryParams(authenticationScheme, displayName: null, configureOptions: configureOptions);
///
@@ -416,7 +491,7 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this Authenti
/// The display name.
/// The configure options.
/// The instance of
- public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions)
+ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions)
=> builder.AddApiKey(authenticationScheme, displayName, configureOptions);
@@ -430,8 +505,13 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this Authenti
///
///
/// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInHeaderOrQueryParams(ApiKeyDefaults.AuthenticationScheme);
+#else
public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInHeaderOrQueryParams(ApiKeyDefaults.AuthenticationScheme);
+#endif
///
/// Adds API Key - In Header Or Query Parameters authentication scheme to the project. It takes a implementation of as type parameter.
@@ -441,8 +521,13 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams
/// The authentication scheme.
/// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInHeaderOrQueryParams(authenticationScheme, configureOptions: null);
+#else
public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, string authenticationScheme) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInHeaderOrQueryParams(authenticationScheme, configureOptions: null);
+#endif
///
/// Adds API Key - In Header Or Query Parameters authentication scheme to the project. It takes a implementation of as type parameter.
@@ -452,8 +537,13 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams
/// The .
/// The instance of
- public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInHeaderOrQueryParams(ApiKeyDefaults.AuthenticationScheme, configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInHeaderOrQueryParams(ApiKeyDefaults.AuthenticationScheme, configureOptions);
+#endif
///
/// Adds API Key - In Header Or Query Parameters authentication scheme to the project. It takes a implementation of as type parameter.
@@ -464,8 +554,13 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParamsThe authentication scheme.
/// The .
/// The instance of
- public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKeyInHeaderOrQueryParams(authenticationScheme, displayName: null, configureOptions: configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInHeaderOrQueryParams(authenticationScheme, displayName: null, configureOptions: configureOptions);
+#endif
///
/// Adds API Key - In Header Or Query Parameters authentication scheme to the project. It takes a implementation of as type parameter.
@@ -477,131 +572,167 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParamsThe display name.
/// The .
/// The instance of
- public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
=> builder.AddApiKey(authenticationScheme, displayName, configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKey(authenticationScheme, displayName, configureOptions);
+#endif
- #endregion // API Key - In Header Or Query Parameters
+ #endregion // API Key - In Header Or Query Parameters
- #region API Key - In Route Values
+ #region API Key - In Route Values
#if NETCOREAPP3_0_OR_GREATER
- ///
- /// Adds API Key - In Route Values authentication scheme to the project.
- /// delegate must be set on the .
- ///
- ///
- /// The instance of
- public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder)
- => builder.AddApiKeyInRouteValues(ApiKeyDefaults.AuthenticationScheme);
-
- ///
- /// Adds API Key - In Route Values authentication scheme to the project.
- /// delegate must be set on the .
- ///
- ///
- /// The authentication scheme.
- /// The instance of
- public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, string authenticationScheme)
- => builder.AddApiKeyInRouteValues(authenticationScheme, configureOptions: null);
-
- ///
- /// Adds API Key - In Route Values authentication scheme to the project.
- /// delegate must be set on the Events property on .
- ///
- ///
- /// The configure options.
- /// The instance of
- public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, Action configureOptions)
- => builder.AddApiKeyInRouteValues(ApiKeyDefaults.AuthenticationScheme, configureOptions);
-
- ///
- /// Adds API Key - In Route Values authentication scheme to the project.
- /// delegate must be set on the Events property on .
- ///
- ///
- /// The authentication scheme.
- /// The configure options.
- /// The instance of
- public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions)
- => builder.AddApiKeyInRouteValues(authenticationScheme, displayName: null, configureOptions: configureOptions);
-
- ///
- /// Adds API Key - In Route Values authentication scheme to the project.
- /// delegate must be set on the Events property on .
- ///
- ///
- /// The authentication scheme.
- /// The display name.
- /// The configure options.
- /// The instance of
- public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions)
- => builder.AddApiKey(authenticationScheme, displayName, configureOptions);
-
-
-
-
-
- ///
- /// Adds API Key - In Route Values authentication scheme to the project. It takes a implementation of as type parameter.
- /// If delegate is set on the then it will be used instead of implementation of .
- ///
- ///
- ///
- /// The instance of
- public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder) where TApiKeyProvider : class, IApiKeyProvider
- => builder.AddApiKeyInRouteValues(ApiKeyDefaults.AuthenticationScheme);
-
- ///
- /// Adds API Key - In Route Values authentication scheme to the project. It takes a implementation of as type parameter.
- /// If delegate is set on the then it will be used instead of implementation of .
- ///
- ///
- ///
- /// The authentication scheme.
- /// The instance of
- public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, string authenticationScheme) where TApiKeyProvider : class, IApiKeyProvider
- => builder.AddApiKeyInRouteValues(authenticationScheme, configureOptions: null);
-
- ///
- /// Adds API Key - In Route Values authentication scheme to the project. It takes a implementation of as type parameter.
- /// If delegate is set on the Events property on then it will be used instead of implementation of .
- ///
- ///
- ///
- /// The .
- /// The instance of
- public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
- => builder.AddApiKeyInRouteValues(ApiKeyDefaults.AuthenticationScheme, configureOptions);
-
- ///
- /// Adds API Key - In Route Values authentication scheme to the project. It takes a implementation of as type parameter.
- /// If delegate is set on the Events property on then it will be used instead of implementation of .
- ///
- ///
- ///
- /// The authentication scheme.
- /// The .
- /// The instance of
- public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
- => builder.AddApiKeyInRouteValues(authenticationScheme, displayName: null, configureOptions: configureOptions);
-
- ///
- /// Adds API Key - In Route Values authentication scheme to the project. It takes a implementation of as type parameter.
- /// If delegate is set on the Events property on then it will be used instead of implementation of .
- ///
- ///
- ///
- /// The authentication scheme.
- /// The display name.
- /// The .
- /// The instance of
- public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TApiKeyProvider : class, IApiKeyProvider
- => builder.AddApiKey(authenticationScheme, displayName, configureOptions);
+ ///
+ /// Adds API Key - In Route Values authentication scheme to the project.
+ /// delegate must be set on the .
+ ///
+ ///
+ /// The instance of
+ public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder)
+ => builder.AddApiKeyInRouteValues(ApiKeyDefaults.AuthenticationScheme);
+
+ ///
+ /// Adds API Key - In Route Values authentication scheme to the project.
+ /// delegate must be set on the .
+ ///
+ ///
+ /// The authentication scheme.
+ /// The instance of
+ public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, string authenticationScheme)
+ => builder.AddApiKeyInRouteValues(authenticationScheme, configureOptions: null);
+
+ ///
+ /// Adds API Key - In Route Values authentication scheme to the project.
+ /// delegate must be set on the Events property on .
+ ///
+ ///
+ /// The configure options.
+ /// The instance of
+ public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, Action? configureOptions)
+ => builder.AddApiKeyInRouteValues(ApiKeyDefaults.AuthenticationScheme, configureOptions);
+
+ ///
+ /// Adds API Key - In Route Values authentication scheme to the project.
+ /// delegate must be set on the Events property on .
+ ///
+ ///
+ /// The authentication scheme.
+ /// The configure options.
+ /// The instance of
+ public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions)
+ => builder.AddApiKeyInRouteValues(authenticationScheme, displayName: null, configureOptions: configureOptions);
+
+ ///
+ /// Adds API Key - In Route Values authentication scheme to the project.
+ /// delegate must be set on the Events property on .
+ ///
+ ///
+ /// The authentication scheme.
+ /// The display name.
+ /// The configure options.
+ /// The instance of
+ public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions)
+ => builder.AddApiKey(authenticationScheme, displayName, configureOptions);
+
+
+
+
+
+ ///
+ /// Adds API Key - In Route Values authentication scheme to the project. It takes a implementation of as type parameter.
+ /// If delegate is set on the then it will be used instead of implementation of .
+ ///
+ ///
+ ///
+ /// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInRouteValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInRouteValues(ApiKeyDefaults.AuthenticationScheme);
+#else
+ public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInRouteValues(ApiKeyDefaults.AuthenticationScheme);
#endif
- #endregion // API Key - In Route Values
+ ///
+ /// Adds API Key - In Route Values authentication scheme to the project. It takes a implementation of as type parameter.
+ /// If delegate is set on the then it will be used instead of implementation of .
+ ///
+ ///
+ ///
+ /// The authentication scheme.
+ /// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInRouteValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInRouteValues(authenticationScheme, configureOptions: null);
+#else
+ public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, string authenticationScheme) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInRouteValues(authenticationScheme, configureOptions: null);
+#endif
- private static AuthenticationBuilder AddApiKey(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions)
+ ///
+ /// Adds API Key - In Route Values authentication scheme to the project. It takes a implementation of as type parameter.
+ /// If delegate is set on the Events property on then it will be used instead of implementation of .
+ ///
+ ///
+ ///
+ /// The .
+ /// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInRouteValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInRouteValues(ApiKeyDefaults.AuthenticationScheme, configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInRouteValues(ApiKeyDefaults.AuthenticationScheme, configureOptions);
+#endif
+
+ ///
+ /// Adds API Key - In Route Values authentication scheme to the project. It takes a implementation of as type parameter.
+ /// If delegate is set on the Events property on then it will be used instead of implementation of .
+ ///
+ ///
+ ///
+ /// The authentication scheme.
+ /// The .
+ /// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInRouteValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInRouteValues(authenticationScheme, displayName: null, configureOptions: configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, string authenticationScheme, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKeyInRouteValues(authenticationScheme, displayName: null, configureOptions: configureOptions);
+#endif
+
+ ///
+ /// Adds API Key - In Route Values authentication scheme to the project. It takes a implementation of as type parameter.
+ /// If delegate is set on the Events property on then it will be used instead of implementation of .
+ ///
+ ///
+ ///
+ /// The authentication scheme.
+ /// The display name.
+ /// The .
+ /// The instance of
+#if NET5_0_OR_GREATER
+ public static AuthenticationBuilder AddApiKeyInRouteValues<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider>(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKey(authenticationScheme, displayName, configureOptions);
+#else
+ public static AuthenticationBuilder AddApiKeyInRouteValues(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions) where TApiKeyProvider : class, IApiKeyProvider
+ => builder.AddApiKey(authenticationScheme, displayName, configureOptions);
+#endif
+
+#endif
+ #endregion // API Key - In Route Values
+
+
+#if NET5_0_OR_GREATER
+ private static AuthenticationBuilder AddApiKey<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyHandler>(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions)
+ where TApiKeyHandler : AuthenticationHandler
+#else
+ private static AuthenticationBuilder AddApiKey(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions)
where TApiKeyHandler : AuthenticationHandler
+#endif
{
// Adds post configure options to the pipeline.
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, ApiKeyPostConfigureOptions>());
@@ -610,9 +741,15 @@ private static AuthenticationBuilder AddApiKey(this Authenticati
return builder.AddScheme(authenticationScheme, displayName, configureOptions);
}
- private static AuthenticationBuilder AddApiKey(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions)
+#if NET5_0_OR_GREATER
+ private static AuthenticationBuilder AddApiKey<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyProvider, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApiKeyHandler>(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions)
+ where TApiKeyProvider : class, IApiKeyProvider
+ where TApiKeyHandler : AuthenticationHandler
+#else
+ private static AuthenticationBuilder AddApiKey(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action? configureOptions)
where TApiKeyProvider : class, IApiKeyProvider
where TApiKeyHandler : AuthenticationHandler