79215186

Date: 2024-11-22 13:30:42
Score: 0.5
Natty:
Report link

Thanks to Shaik Abid Hussain's Idea i found a solution for .Net 8:

Simply add this line:

options.UseSecurityTokenValidators = true;

Into the .AddJwtBearer(options =>{}) anonym function in the Program.cs File. This is what it looks like for me now:

var key = Encoding.ASCII.GetBytes(builder.Configuration["Jwt:Secret"]);
builder.Services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
    options.RequireHttpsMetadata = false;
    options.SaveToken = true;
    options.TokenValidationParameters = new TokenValidationParameters
    {
        ValidateIssuerSigningKey = true,
        IssuerSigningKey = new SymmetricSecurityKey(key),
        ValidateIssuer = false,
        ValidateAudience = false
    };
    options.UseSecurityTokenValidators = true;
});
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Aquos00