在ASP.NET Core API项目中,我需要验证位于与Authorization标头不同的标头中的另一个JWT Bearer令牌。例如,假设发送一个GET请求以获得产品到
/api/products
,其中包含在名为AccessToken
的标头中的Bearer令牌。curl --location --request GET 'https://localhost/api/products' \
--header 'AccessToken: <bearer_token>'
我正在参考 Microsoft.AspNetCore.Authentication.JwtBearer 包,并在 API 项目中进行身份验证,类似于这样:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options => Configuration.Bind("JwtSettings", options));
然而,在JwtBearerOptions类中,我找不到任何关于头部名称的信息。
如何配置JWT身份验证以从名为“AccessToken”的标头读取JWT? 使用Microsoft.AspNetCore.Authentication.JwtBearer包是否可行?