Using using Microsoft.AspNetCore.Authentication.JwtBearer;
I have been unable to figure out how to change the "Bearer " key in the header to something else, in this case I'd like it to be "Token ".
Startup.cs
services.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(x =>
{
x.RequireHttpsMetadata = false;
x.SaveToken = true;
x.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = false,
ValidateAudience = false,
ValidateLifetime = true,
ValidIssuer = Configuration.GetValue<string>("JwtIssuer"),
ValidAudience = Configuration.GetValue<string>("JwtAudience"),
};
x.Events = new JwtBearerEvents
{
OnAuthenticationFailed = context =>
{
if (context.Exception.GetType() == typeof(SecurityTokenExpiredException))
{
context.Response.Headers.Add("Token-Expired", "true");
}
return Task.CompletedTask;
}
};
});
When I do something like
GET {{protocol}}://{{url}}/users HTTP/1.1
Authorization: Bearer {{token}}
The token works, but I could not figure out how to customize it to be something like.
GET {{protocol}}://{{url}}/users HTTP/1.1
Authorization: Token {{token}}
authorization: header xxx
toauthorization: token xxx
– Windsail