Skip to content

Commit

Permalink
fix: use AddAuthorizationBuilder instead of AddAuthorization
Browse files Browse the repository at this point in the history
  • Loading branch information
tnotheis committed Dec 2, 2024
1 parent bceae43 commit 64d63cc
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void AddCustomAspNetCore(this IServiceCollection services,
options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
});

services.AddAuthentication().AddJwtBearer(options =>
services.AddAuthentication().AddJwtBearer("default", options =>
{
var privateKeyBytes = Convert.FromBase64String(configuration.Authentication.JwtSigningCertificate);
#pragma warning disable SYSLIB0057 // The constructor is obsolete. But I didn't manage to get the suggested alternative to work.
Expand All @@ -75,7 +75,13 @@ public static void AddCustomAspNetCore(this IServiceCollection services,
options.TokenValidationParameters.ValidateIssuer = false;
options.TokenValidationParameters.ValidateAudience = false;
});
services.AddAuthorization();

services.AddAuthorizationBuilder()
.AddDefaultPolicy("default", policy =>
{
policy.AddAuthenticationSchemes("default");
policy.RequireAuthenticatedUser();
});

services.AddHttpContextAccessor();

Expand Down

0 comments on commit 64d63cc

Please sign in to comment.