目前遵循这个教程关于如何实现OAuth JWT身份验证。目前被困在两件事上,这已经成了一件很难解决的事情。
app.UseJwtBearerAuthentication(
new JwtBearerAuthenticationOptions
{
AuthenticationMode = AuthenticationMode.Active,
AllowedAudiences = new[] { audienceId },
IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
{
new SymmetricKeyIssuerSecurityTokenProvider(issuer, audienceSecret)
}
});如下图所示,错误如下:

不知道为什么我要得到这个错误,因为所有必要的软件包都已安装。另一方面,如果我选择使用此IssuerSecurityKeyProviders或运行带有错误的构建,则它将生成令牌,但当我试图访问api上的任何已创作终结点时,我会得到可怕的“消息”:“此请求的授权已被拒绝”。
当我调试令牌时,一切似乎都是匹配的。发布者是相同的,受众id是相同的,而且用户也存在于数据库中,但是changepassword端点总是失败,如下面的屏幕截图所示。

最后,但并非最不重要的是,我可以学习一个好的教程,帮助我使用JWT和OWIN建立和运行Web身份验证。大多数已经过时,而且软件包在过去几年中已经发生了变化,例如这个一,很难找到所遇到的问题的答案。触碰令人沮丧
发布于 2019-06-23 17:26:58
更新版本的"Microsoft.Owin.Security.Jwt“库可能有一些需要考虑的重命名。试一试:
// Api controllers with an [Authorize] attribute will be validated with JWT
app.UseJwtBearerAuthentication(
new JwtBearerAuthenticationOptions
{
AuthenticationMode = AuthenticationMode.Active,
AllowedAudiences = new[] { audienceId },
IssuerSecurityKeyProviders = new IIssuerSecurityKeyProvider[] {
new SymmetricKeyIssuerSecurityKeyProvider(issuer, audienceSecret)
}
});这实质上用"IssuerSecurityKeyProviders“代替"IssuerSecurityTokenProviders”,用"IIssuerSecurityKeyProvider“代替"IIssuerSecurityTokenProvider”。
https://stackoverflow.com/questions/56517399
复制相似问题