Skip to content
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ docfx.zip
# Ignoring Misc
.DS_Store
.github/.DS_Store

# Ignoring C# Dev Kit language service cache files
*.lscache
30 changes: 13 additions & 17 deletions Auth0.AspNetCore.Authentication.Api.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,21 @@
builder.Services.AddSwaggerGen();

// Adds Auth0 JWT validation to the API
builder.Services.AddAuth0ApiAuthentication(options =>
{
options.JwtBearerOptions = new JwtBearerOptions
{
Audience = builder.Configuration["Auth0:Audience"]
?? throw new InvalidOperationException("Auth0:Audience is required")
};
options.Domain = builder.Configuration["Auth0:Domain"]
?? throw new InvalidOperationException("Auth0:Domain is required");
options.JwtBearerOptions.Events = new JwtBearerEvents
// Configuration is automatically bound from appsettings.json "Auth0" section
builder.Services.AddAuth0ApiAuthentication(
builder.Configuration.GetSection("Auth0"),
configureJwtBearer: jwt =>
{
// Custom event just to log the token received in the request.
OnMessageReceived = context =>
jwt.Events = new JwtBearerEvents
{
Console.WriteLine($"Token extracted? : {(!string.IsNullOrEmpty(context.Token) ? "yes" : "no")}");
return Task.CompletedTask;
}
};
}).WithDPoP();
// Custom event just to log the token received in the request.
OnMessageReceived = context =>
{
Console.WriteLine($"Token extracted? : {(!string.IsNullOrEmpty(context.Token) ? "yes" : "no")}");
return Task.CompletedTask;
}
};
}).WithDPoP();

builder.Services.AddAuthorization();

Expand All @@ -45,7 +41,7 @@
app.UseAuthentication();
app.UseAuthorization();

app.MapGet("/open-endpoint", () =>

Check warning on line 44 in Auth0.AspNetCore.Authentication.Api.Playground/Program.cs

View workflow job for this annotation

GitHub Actions / build

'OpenApiEndpointConventionBuilderExtensions.WithOpenApi<TBuilder>(TBuilder)' is obsolete: 'WithOpenApi is deprecated and will be removed in a future release. For more information, visit https://aka.ms/aspnet/deprecate/002.' (https://aka.ms/aspnet/deprecate/002)
{
var responseMessage = "This endpoint is available to all users.";
return responseMessage;
Expand All @@ -53,7 +49,7 @@
.WithName("AccessOpenEndpoint")
.WithOpenApi();

app.MapGet("/restricted-endpoint", () =>

Check warning on line 52 in Auth0.AspNetCore.Authentication.Api.Playground/Program.cs

View workflow job for this annotation

GitHub Actions / build

'OpenApiEndpointConventionBuilderExtensions.WithOpenApi<TBuilder>(TBuilder)' is obsolete: 'WithOpenApi is deprecated and will be removed in a future release. For more information, visit https://aka.ms/aspnet/deprecate/002.' (https://aka.ms/aspnet/deprecate/002)
{
var responseMessage = "You are special. This endpoint is available only to select users.";
return responseMessage;
Expand Down
Loading
Loading