在一些情况下不从Request Header
中获取JWT
,可以同URL
中获取。
重点在于account_token
services
.AddAuthentication()
.AddJwtBearer(options =>
{
options.Authority = configuration["AuthServer:Authority"];
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
options.Audience = "ContestPlatform";
options.BackchannelHttpHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
};
options.Events = new JwtBearerEvents
{
OnMessageReceived = async context =>
{
context.Token = context.Request.Query["account_token"];
await Task.CompletedTask;
}
};
});