尝试在多个域上使用 Azure AFDS 登录

Posted

技术标签:

【中文标题】尝试在多个域上使用 Azure AFDS 登录【英文标题】:Trying to login with Azure AFDS on multiple domains 【发布时间】:2021-11-14 20:03:37 【问题描述】:

我正在尝试使用 Umbraco 网站连接到 Azure AD 服务器。 首先,我不了解 Azure。有第三方负责管理 Azure 部分。

我们使用 OWIN 通过 OpenID 连接到 Azure。 启动时:

public void ConfigureAuth(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 = redirectUri,
            Scope = OpenIdConnectScope.OpenIdProfile,
            ResponseType = OpenIdConnectResponseType.IdToken,
            TokenValidationParameters = new TokenValidationParameters()
                ValidateIssuer = false
            ,
            Notifications = new OpenIdConnectAuthenticationNotifications
                AuthenticationFailed = OnAuthenticationFailed
            
        );
    

SurfaceController 中的 SignIn 函数:

public void SignIn(string ReturnUrl = "/")
    if (!Request.IsAuthenticated) 
        HttpContext.GetOwinContext().Authentication.Challenge(
            new AuthenticationProperties  RedirectUri = ReturnUrl ,
            OpenIdConnectAuthenticationDefaults.AuthenticationType);
    

非工作部分来了。 如果我在本地域测试该站点(仅在我们办公室内可用),它可以工作。 如果我在一个公开可用的暂存域上测试这个站点,它就可以工作。 如果我在一个活动域上测试这个网站,它就可以工作。

但是,一旦我更改了子域,我就会收到“RequireNonce”错误发送到工作域。 例如: https://customer.localdomain.com -> 登录 -> 我返回登录 https://customer.localdomain.com。 https://test.localdomain.com -> 登录 -> 我返回 https://customer.localdomain.com(注意域),出现“Nonce-error”。

https://customer.stagingdomain.com -> 登录 -> 我返回登录 https://customer.stagingdomain.com。 https://test.stagingdomain.com -> 登录 -> 我返回 https://customer.stagingdomain.com(注意域),出现“Nonce-error”。

https://www.livedomain.com -> 登录 -> 我返回登录 https://www.livedomain.com。 https://test.livedomain.com -> 登录 -> 我返回 https://www.livedomain.com(注意域),出现“Nonce-error”。

完整的错误是:

IDX21323: 
RequireNonce is '[PII is hidden]'. 
OpenIdConnectProtocolValidationContext.Nonce was null, 
OpenIdConnectProtocol.ValidatedIdToken.Payload.Nonce was not null. 
The nonce cannot be validated. 
If you don't need to check the nonce, set OpenIdConnectProtocolValidator.
RequireNonce to 'false'. Note if a 'nonce' is found it will be evaluated.

我们可以做些什么来解决这个问题?我们的客户有几个子域(单独的站点)都需要此登录功能。 我们尝试将子域添加到 Azure 中的回复列表(好吧,第三方为我们添加了它们),但这并没有解决问题。

是否可以在某处关闭 RequireNonce?

【问题讨论】:

【参考方案1】:

感谢JamesHamil-MSFT 发布您的suggestion 作为回答以帮助其他社区成员。

“问题是那个时候还是自动引用程序服务绑定了一个自定义域名。 应用网管配置完成后。修改自定义域名的Host IP指向一个公共IP,即网关。” 请尝试检查您的域是否配置正确并指向正确的网关。"

更多信息请参考以下链接:

。 Configure App Service with Application Gateway using PowerShell | MS DOC.

。 SO THREAD 类似问题。

【讨论】:

以上是关于尝试在多个域上使用 Azure AFDS 登录的主要内容,如果未能解决你的问题,请参考以下文章

登录后如何获取用户名?我正在尝试使用 MSAL(@azure/msal-angular)进行 Azure 登录

使用多个域登录 Facebook

如果我们有多个重定向 uri,那么在 Azure AD 登录后将选择哪一个

使用 Azure 登录凭据通过 FTP 连接到 Azure 网站

Xamarin Azure AD B2C 登录,卡在登录页面

更改密码后无法使用Visual Studio 2013登录Windows azure帐户