在一些情况下不从Request Header中获取JWT,可以同URL中获取。

    重点在于account_token

    1. services
    2. .AddAuthentication()
    3. .AddJwtBearer(options =>
    4. {
    5. options.Authority = configuration["AuthServer:Authority"];
    6. options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
    7. options.Audience = "ContestPlatform";
    8. options.BackchannelHttpHandler = new HttpClientHandler
    9. {
    10. ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
    11. };
    12. options.Events = new JwtBearerEvents
    13. {
    14. OnMessageReceived = async context =>
    15. {
    16. context.Token = context.Request.Query["account_token"];
    17. await Task.CompletedTask;
    18. }
    19. };
    20. });