微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – UseJwtBearerAuthentication签名密钥

我正在尝试使用JwtBearerMiddleware在我的AspNetCore MVC应用程序(仅限Web API)中实现JWT承载身份验证,但我收到了带有标头的401响应:
WWW-Authenticate: Bearer error="invalid_token",error_description="The signature key was not found"

Startup.cs中的相关代码如下所示:

app.UseJwtBearerAuthentication(new JwtBearerOptions
{
    Authority = "https://example.okta.com",Audience = "myClientId"
});

使用权限URL,我希望中间件从https://example.okta.com/.well-kNown/openid-configuration查询我的身份提供程序元数据,以获取jwks_uri,然后从https://获取签名密钥example.okta.com/oauth2/v1/keys.我不认为这种情况正在发生.我需要做些什么才能找到并使用签名密钥?谢谢

解决方法

在遵循引用并深入研究 AspNet Security repo(特别是JwtBearerHandler和JwtBearerMiddleware类)之后,这导致了我在 Azure Extensions repo中的Microsoft.IdentityModel命名空间(首先是ConfigurationManager< T>类,然后是OpenIdConnectConfigurationRetriever类(GetAsync方法),然后到JsonWebKeySet.GetSigningKeys()方法),我终于发现JwtBearerMiddleware确实从元数据中的jwks_uri获取了密钥.唷.

那为什么不工作呢?我之前应该检查的是,持票人JWT标题中的孩子实际上并不匹配jwks_uri中的任何一个孩子,因此没有找到.这是我作为持票人令牌发送的access_code.另一方面,id_token确实有一个匹配的孩子,所以使用它而不是它的工作!

我读过:

The OIDC Access Token is applicable only for the Okta
/oauth2/v1/userinfo endpoint and thus should be treated as opaque by
the application. The application does not need to validate it since it
should not be used against other resource servers. The format of it
and the key used to sign it are subject to change without prior
notice.
07002

…所以我不能使用访问令牌.

原文地址:https://www.jb51.cc/csharp/99961.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐