【问题标题】:IDX21323: RequireNonce is '[PII is hidden]'. OpenIdConnectProtocolValidationContext.Nonce was nullIDX21323:RequireNonce 是“[PII 已隐藏]”。 OpenIdConnectProtocolValidationContext.Nonce 为空
【发布时间】:2021-11-10 11:31:08
【问题描述】:

我知道同一线程上有多个线程,但没有一个解决方案适合我,有什么解决方案吗?奇怪的是,当我在 IE 中运行应用程序时,它在 Edge 中运行时遇到了这个问题

IDX21323:RequireNonce 是“[PII 被隐藏]”。 OpenIdConnectProtocolValidationContext.Nonce 为空, OpenIdConnectProtocol.ValidatedIdToken.Payload.Nonce 不为空。这 nonce 无法验证。如果您不需要检查随机数,请设置 OpenIdConnectProtocolValidator.RequireNonce 为“假”。请注意,如果 找到'nonce',它将被评估。

这里是代码

public class Startup
{
    // The Client ID is used by the application to uniquely identify itself to Azure AD.
    string clientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"];

    // RedirectUri is the URL where the user will be redirected to after they sign in.
    string redirectUri = System.Configuration.ConfigurationManager.AppSettings["RedirectUri"];

    // Tenant is the tenant ID (e.g. contoso.onmicrosoft.com, or 'common' for multi-tenant)
    static string tenant = System.Configuration.ConfigurationManager.AppSettings["Tenant"];

    // Authority is the URL for authority, composed by Microsoft identity platform endpoint and the tenant name (e.g. https://login.microsoftonline.com/contoso.onmicrosoft.com/v2.0)
    string authority = String.Format(System.Globalization.CultureInfo.InvariantCulture, System.Configuration.ConfigurationManager.AppSettings["Authority"], tenant);

    /// <summary>
    /// Configure OWIN to use OpenIdConnect 
    /// </summary>
    /// <param name="app"></param>
    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,
            Authority = authority,
            RedirectUri = redirectUri,
            // PostLogoutRedirectUri is the page that users will be redirected to after sign-out. In this case, it is using the home page
            PostLogoutRedirectUri = redirectUri,
            Scope = OpenIdConnectScope.OpenIdProfile,
            // ResponseType is set to request the code id_token - which contains basic information about the signed-in user
            ResponseType = OpenIdConnectResponseType.CodeIdToken,
            // OpenIdConnectAuthenticationNotifications configures OWIN to send notification of failed authentications to OnAuthenticationFailed method
            Notifications = new OpenIdConnectAuthenticationNotifications
            {
                AuthenticationFailed = OnAuthenticationFailed
            }
        }
    );
    }

    /// <summary>
    /// Handle failed authentication requests by redirecting the user to the home page with an error in the query string
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private Task OnAuthenticationFailed(AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> context)
    {
        context.HandleResponse();
        context.Response.Redirect("/?errormessage=" + context.Exception.Message);
        return Task.FromResult(0);
    }
}

我厌倦了可用的选项,但没有任何效果,是否有任何可能的解决方案

参考了这个OpenIdConnectProtocolValidationContext.Nonce was null

【问题讨论】:

  • 向我们展示您的尝试,而不仅仅是告诉我们。提供minimal reproducible example
  • 没有特定代码我已经创建了一个示例应用程序,我在从 azure 创建应用程序后下载了该示例应用程序
  • 你解决了吗?

标签: asp.net azure-active-directory


【解决方案1】:

请尝试更新您的 Microsoft.Owin.Security.OpenIdConnect 软件包以匹配您其他 Owin 软件包的版本号,如 this related thread 中所述。

Microsoft.Owin [4.1.1]
Microsoft.Owin.Security [4.1.1]
Microsoft.Owin.Security.Cookies [4.1.1]

如果您使用的是 Google Chrome,请确保您也已更新到最新版本的 Chrome,或者在其他浏览器中进行测试。 (This guide 讨论了导致此错误的 Chrome 问题。)

【讨论】:

  • 我将它们升级到 4.1.0 但问题仍然存在
  • 不确定进程是否正确context.SkipToNextMiddleware();
  • 你能分享更多关于你尝试了哪些步骤的细节吗?
  • 我刚刚在这里添加了这个private Task OnAuthenticationFailed(AuthenticationFailedNotification&lt;OpenIdConnectMessage, OpenIdConnectAuthenticationOptions&gt; context) { context.SkipToNextMiddleware(); return Task.FromResult(0); }
  • 这不是答案
猜你喜欢
  • 2021-09-28
  • 1970-01-01
  • 2019-09-15
  • 2018-12-15
  • 1970-01-01
  • 2018-11-08
  • 2019-08-13
  • 1970-01-01
  • 2020-04-22
相关资源
最近更新 更多