我正在尝试使用Owin通过ASP NET应用程序实现Azure AD身份验证。
我使用的代码如下:
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
RedirectUri = redirectUri,
PostLogoutRedirectUri = redirectUri,
Scope = OpenIdConnectScope.OpenId,
ResponseType = OpenIdConnectResponseType.CodeIdToken,
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = OnAuthenticationFailed,
AuthorizationCodeReceived = OnAuthorizationCodeReceived,
}
}
);
我得到以下错误:IDX10503: Signature validation failed. Token does not have a kid. Keys tried: 'System.Text.StringBuilder'
我检查了代币,孩子在里面。根据:https://learn.microsoft.com/en-us/azure/active-directory/develop/signing-key-rollover,NET OWIN OpenID Connect已经具有自动处理密钥翻转的必要逻辑。
1条答案
按热度按时间fdbelqdn1#
错误消息
IDX10503: Signature validation failed. Token does not have a kid. Keys tried: 'System.Text.StringBuilder'
表示正在验证的JSON Web Token(JWT)缺少kid
(密钥标识符)声明,这对于标识用于签名JWT的密钥至关重要。要解决这个问题,可以使用
OpenIdConnectAuthenticationOptions
类,它的特点是在令牌验证后触发SecurityTokenValidated
事件。在事件处理程序中,您可以使用其他声明(如ClaimTypes.Name
声明)来增强标识。请确保您已安装以下软件包
结果
