【问题标题】:OpenIdConnectProtocol.ValidatedIdToken.Payload.Nonce was not null - Azure AD, OpenIDConnect, C#, asp.netOpenIdConnectProtocol.ValidatedIdToken.Payload.Nonce 不为空 - Azure AD、OpenIDConnect、C#、asp.net
【发布时间】:2022-01-23 01:34:18
【问题描述】:

由于某种原因,我在尝试将我的身份验证代码兑换为访问令牌后收到以下错误:

错误:IDX21323:RequireNonce 是“[PII 被隐藏]”。 OpenIdConnectProtocolValidationContext.Nonce 为空,OpenIdConnectProtocol.ValidatedIdToken.Payload.Nonce 不为空。无法验证随机数。如果您不需要检查 nonce,请将 OpenIdConnectProtocolValidator.RequireNonce 设置为“false”。请注意,如果找到“nonce”,则会对其进行评估。

我在 IIS Express 上运行。 OWIN startup.cs如下:

public void Configuration(IAppBuilder app)
{
    app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
    app.UseCookieAuthentication(new CookieAuthenticationOptions());
    app.UseOpenIdConnectAuthentication(
        new OpenIdConnectAuthenticationOptions
        {
            // Sets the ClientId, authority, RedirectUri as obtained from web.config
            ClientId = clientId,
            ClientSecret = clientSecret,
            Authority = authority,
            RedirectUri = redirectUri,
            PostLogoutRedirectUri = redirectUri,
            Scope = OpenIdConnectScope.OpenIdProfile,
            RedeemCode = true,
            ResponseType = OpenIdConnectResponseType.Code,

            TokenValidationParameters = new TokenValidationParameters()
            {
                ValidateIssuer = false,
            },
            Notifications = new OpenIdConnectAuthenticationNotifications
            {
                AuthenticationFailed = OnAuthenticationFailed,
            },
        }
    );
}

据我所知,中间件管理流程,我只是指示中间件提供一堆配置。我需要帮助以了解错误并尝试找到解决方案。

【问题讨论】:

    标签: c# asp.net openid-connect katana


    【解决方案1】:

    使用 nuget 包管理器将所有相关包更新到最新版本似乎已经解决了这个问题。

    【讨论】: