gpt4 book ai didi

.net-core - 承载错误 ="invalid_token", error_description ="The signature is invalid"

转载 作者:行者123 更新时间:2023-12-04 15:17:59 25 4
gpt4 key购买 nike

我有一个从 azure 请求 token 的角度应用程序。登录进行得很顺利,我得到了一个 token 。此 token 现在从 angular 应用程序发送到网络核心 webapi 应用程序。 Net core 应该验证这个 token 但是失败了。我认为 webapi 还应该联系 azure 来验证 token ,因为它不知道验证 token 所需的私钥和公钥。

目前尚不清楚它为什么失败。 angular 应用程序和 webapi 都在我的计算机上本地运行。

错误是:Microsoft.IdentityModel.Tokens.SecurityTokenInvalidSignatureException: 'IDX10500: Signature validation failed. No security keys were provided to validate the signature.'
我的网络核心 2 配置是:

var tokenValidationParameters = new TokenValidationParameters
{

RequireExpirationTime = true,
RequireSignedTokens = false,
ValidateIssuerSigningKey = true,
ValidateIssuer = true,
ValidIssuer = "8d708afe-2966-40b7-918c-a39551625958",
ValidateAudience = true,
ValidAudience = "https://sts.windows.net/a1d50521-9687-4e4d-a76d-ddd53ab0c668/",
ValidateLifetime = false,
ClockSkew = TimeSpan.Zero
};
services.AddAuthentication(options =>
{
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;

}).AddJwtBearer(options =>
{

options.Audience = "8d708afe-2966-40b7-918c-a39551625958";
options.ClaimsIssuer = "https://sts.windows.net/a1d50521-9687-4e4d-a76d-ddd53ab0c668/";
options.RequireHttpsMetadata=false;
options.TokenValidationParameters = tokenValidationParameters;
options.SaveToken = true;
});

最佳答案

你有很多配置:)

两个强制性设置是受众和权威:

services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(o =>
{
o.Audience = "8d708afe-2966-40b7-918c-a39551625958";
o.Authority = "https://login.microsoftonline.com/a1d50521-9687-4e4d-a76d-ddd53ab0c668/";
});

您缺少授权,因此它不知道从哪里加载签名公钥。

关于.net-core - 承载错误 ="invalid_token", error_description ="The signature is invalid",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48944697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com