【问题标题】:Dotnet Framework Azure AD connected serviceDotnet Framework Azure AD 连接服务
【发布时间】:2021-09-06 01:45:16
【问题描述】:

我正在尝试让 Azure AD 连接服务为我的 dotnet 框架应用程序工作。我浏览了该向导,它添加了它工作所需的必要依赖项和文件。我遇到的问题是它不能可靠地工作。所以我回滚了,我只是在本地工作。但是,如果我输入 localhost/Athena 它将不起作用,但它会将 /signin-oidc 留在 URL 的末尾。当我手动删除最后一部分时,页面工作正常。我得到的错误是

IDX21323:RequireNonce 是“System.Boolean”。 OpenIdConnectProtocolValidationContext.Nonce 为空。

如果我输入 https://localhost/Athena,它每次都能正常工作。下面是我的 Startup.Auth.cs 文件中的代码。

public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = "8675309",
                Authority = authority,                    
                CallbackPath = new PathString("/signin-oidc"),
                //Tried with the below redirecturi and I still have the same issues.
                //RedirectUri = "https://localhost/Athena/signin-oidc"
            });
    }

【问题讨论】:

    标签: asp.net .net asp.net-mvc azure azure-active-directory


    【解决方案1】:

    当 OpenIdConnect 中间件遇到无效的 nonce 或缺少 nonce cookie 时,会发生此异常。 尝试进行以下配置。

    配置startup.cs如下

    AuthenticationType = “ApplicationCookie”,
    CookieSameSite = SameSiteMode.None,
    CookieSecure = CookieSecureOption.Always
     

    检查/配置 web.config

    <system.web>
    <sessionState cookieSameSite=”None”/>
    <httpCookies requireSSL=”true” />
    </system.web>

    注意:确保您的所有网站流量都超过 https。

    初始化代码因平台而异。对于 ASP.NET Core 和 ASP.NET,登录用户被委派给 OpenID Connect 中间件。需要进行一些配置才能使它们适应 Microsoft 标识平台。

    与 ASP.NET Web 应用和 Web API 中的身份验证相关的代码位于 App_Start/Startup.Auth.cs 文件中。

         public void ConfigureAuth(IAppBuilder app)
         {
          app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
    
          app.UseCookieAuthentication(new CookieAuthenticationOptions());
    
          app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
             // Authority` represents the identity platform endpoint - https://login.microsoftonline.com/common/v2.0.
             // `Scope` describes the initial permissions that your app will need.
             //  See https://azure.microsoft.com/documentation/articles/active-directory-v2-scopes/.
             ClientId = clientId,
             Authority = String.Format(CultureInfo.InvariantCulture, aadInstance, "common", "/v2.0"),
             RedirectUri = redirectUri,
             Scope = "openid profile",
             PostLogoutRedirectUri = redirectUri,
            });
         }

    【讨论】:

    • 感谢您提出的这个快速的问题。我的 Startup.cs 文件非常基础。公共部分类启动{公共无效配置(IAppBuilder应用程序){ConfigureAuth(应用程序); } }
    • 你为 Startup.cs 文件提供的代码我可以把它放在 Startup.Auth.cs 文件中,类似于:docs.microsoft.com/en-us/aspnet/samesite/csmvc
    • 我进行了这些更改,但仍然得到相同的结果
    • 尝试在此处参考此类似问题的答案,这可能会有所帮助 - stackoverflow.com/questions/49944071/…
    猜你喜欢
    • 2016-09-24
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多