-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add NativeAOT support for JwtBearer Authentication #47487
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
Comments
Thanks for contacting us. We're moving this issue to the |
We don't need to fix #47410 issue to enable this scenario. The app will be larger than it needs to be, but it will still work once AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#2035 is implemented. |
This now works with the latest rc1 SDKs and using System.Security.Claims;
using System.Text.Json.Serialization.Metadata;
var builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureHttpJsonOptions(options =>
{
options.SerializerOptions.TypeInfoResolver = JsonTypeInfoResolver.Combine();
});
builder.Services.AddAuthentication().AddJwtBearer();
builder.Services.AddAuthorization();
var app = builder.Build();
app.MapGet("/", () => "Hello, World!");
app.MapGet("/secret", (ClaimsPrincipal user) => $"Hello {user.Identity?.Name}. My secret")
.RequireAuthorization();
app.Run(); You do need to configure the |
We need the app to be able to be published with no warnings in order to officially support this scenario. AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#2035 will allow for no warnings. |
This is now complete and works with NativeAOT. We have https://github.com/aspnet/Benchmarks/blob/5ea00ac8d1471088ff96831156f7c8533da8f514/src/BenchmarksApps/TodosApi/TodosApi.csproj#L19 which uses this in a benchmark app. |
The following program produces AOT warnings and doesn't work after being published to NativeAOT:
We should enable this to work in ASP.NET 8 with NativeAOT.
Underlying issues:
The text was updated successfully, but these errors were encountered: