auth0-aspnetcore-webapi-samples icon indicating copy to clipboard operation
auth0-aspnetcore-webapi-samples copied to clipboard

.NET 6 Support

Open ICanDoThings2 opened this issue 2 years ago • 2 comments

Will support come for this for .NET 6? I was using the tutorial here; https://auth0.com/docs/quickstart/backend/aspnet-core-webapi/01-authorization but it doesn't seem for the recent version, which has no more startup.cs , and it looks like a lot of the project was updated last years ago.

ICanDoThings2 avatar Aug 09 '22 23:08 ICanDoThings2

Hey,

.NET 6 on its own can still use a startup file. I assume you are talking about the minimal API that comes with .NET 6? Even then you could have a Startup file if you'd like: https://www.c-sharpcorner.com/article/how-to-add-startup-cs-class-in-asp-net-core-6-project/

That said, that startup file is just some syntactic sugar, so you should be able to use it in a comparable way without a Startup file:

var builder = WebApplication.CreateBuilder(args);

// ...

string domain = $"https://{builder.Configuration["Auth0:Domain"]}/";
builder.Services
    .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =>
    {
        options.Authority = domain;
        options.Audience = builder.Configuration["Auth0:Audience"];
        options.TokenValidationParameters = new TokenValidationParameters
        {
            NameClaimType = ClaimTypes.NameIdentifier
        };
    });

var app = builder.Build();

// ...
app.UseAuthentication();
app.UseAuthorization();
app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
    });
app.Run();

Would that help?

frederikprijck avatar Aug 11 '22 15:08 frederikprijck

Yeah. I see what you're getting. The Program.cs file exists still, and I figure I could plop it in that. It was giving me some weirdness with setting the domain though and reading it from the JSON file.

ICanDoThings2 avatar Aug 11 '22 22:08 ICanDoThings2

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

stale[bot] avatar Nov 13 '22 02:11 stale[bot]