首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >多重子域上的网站Azure连接

多重子域上的网站Azure连接
EN

Stack Overflow用户
提问于 2022-06-08 09:04:19
回答 1查看 90关注 0票数 0

我们在我们的网络服务器上托管一个网站。该网站需要连接到Azure/Adfs。用户需要通过Azure/Adfs登录才能访问站点的某些部分。

但它只起一半的作用。我可以在"customer.nl“上连接,但是在"subdomain.customer.nl”上我会得到一个“现在的错误”。

有一个"Startup“类,它继承自"UmbracoDefaultOwinStartup”(普通OwinStartup的Umbraco覆盖)。这个类有一个"ConfigureAuth“方法,它设置配置参数。其中一个是RedirectUri,它被设置为"customer.nl“(通过web.config)。

“启动”代码:

代码语言:javascript
运行
复制
[assembly: OwinStartup(typeof(Ip.Startup))]
namespace Customername {
    public class Startup : UmbracoDefaultOwinStartup {
        string redirectUri = System.Configuration.ConfigurationManager.AppSettings["RedirectUri"];

        public new void Configuration(IAppBuilder app) {
            ConfigureAuth(app);
            app.MapSignalR();
            base.Configuration(app);
        }

        public void ConfigureAuth(IAppBuilder app) {
            app.SetDefaultSignInAsAuthenticationType(
                CookieAuthenticationDefaults.AuthenticationType);
            app.UseCookieAuthentication(new CookieAuthenticationOptions(){ 
                CookieManager = new SystemWebCookieManager()
            });
            app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions {
                ClientId = clientId,
                Authority = authority,
                RedirectUri = redirectUri,
                PostLogoutRedirectUri = redirectUri,
                Scope = OpenIdConnectScope.OpenIdProfile,
                ResponseType = OpenIdConnectResponseType.IdToken,
                TokenValidationParameters = new TokenValidationParameters() {
                    ValidateIssuer = false
                },
                Notifications = new OpenIdConnectAuthenticationNotifications {
                    AuthenticationFailed = OnAuthenticationFailed
                }
            });
        }
    }
}

如果我尝试登录"subdomain.customer.nl",我会重定向到login.microsoftonline.com,但是我在URL中看到了一个"redirect_url=customer.nl“。

重定向未经身份验证的用户的函数是:

代码语言:javascript
运行
复制
public void SignIn(string ReturnUrl = "/") {
    if (!Request.IsAuthenticated) {
        HttpContext.GetOwinContext().Authentication.Challenge(
            new AuthenticationProperties { RedirectUri = ReturnUrl },
            OpenIdConnectAuthenticationDefaults.AuthenticationType);
        }
    }
}

但是,在此函数中更改RedirectUri并不会更改login.microsoftonline.com url中的“Redirect_Uri”。

如果我在subdomain.customer.nl上登录,我将使用以下查询字符串返回到customer.nl (我已经解码了URL):

代码语言:javascript
运行
复制
https://www.customer.nl/?errormessage=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.

我的猜测是,当redirect_uri不匹配源-url (subdomain.customer.nl != customer.nl)时,就会弹出当前错误。

这是正确的吗?如果是这样,我如何将Redirect_Uri更改为用户正在访问的子域?看来,在创业时设置它并不是一条路。

EN

回答 1

Stack Overflow用户

发布于 2022-06-10 13:25:45

·首先,我建议您确保公共DNS记录存在于您希望通过基本域连接的子域,即‘customer.nl’。子域的公共DNS记录可以是“A”主机记录、“TXT”记录,但需要在公共DNS服务器和指向公共IP地址的中正确配置,如果独立的web应用程序托管在它们上的话。

·其次,由于您似乎使用Azure AD身份验证在您的网站中重定向到子域,我建议您为基本域的Azure AD注册应用程序中的相关子域配置重定向URI,以便在成功的Azure AD身份验证之后,web应用程序按照需要的正确地重定向到子域页。

有关上述内容的更多信息,请参阅下面的文档链接:-

https://learn.microsoft.com/en-us/azure/app-service/configure-authentication-provider-aad

,但在此函数中更改RedirectUri并不会更改login.microsoftonline.com url中的“Redirect_Uri”

You can do the above by delegating the required API permissions and scope to the Azure function application in your registered Azure AD application。请参阅下面的文档链接以获得您的参考:-

https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent

此外,用于身份验证请求和响应的域需要匹配,因为它存储用于CSRF登录攻击缓解的“nonce”和“state”。因此,我建议您考虑以下针对不同客户的场景(根据您的重定向机制),并利用SSO:-

( a) 用户登录到第一个应用程序(customer.nl)中。回调URL属于这个应用程序

( b) 在处理回调后(在‘parseHash’回调函数上),将用户重定向到子域URL

c) 当用户登陆子域URL应用程序时,应用程序将看到用户没有会话,并要求Azure进行身份验证(授权()或checkSession())。如果用户在Azure中已经有一个会话,则不会向用户发出提示,并且将向应用程序提供一个新的身份验证响应。

如果您使用的是通用登录(而不是上面的嵌入式登录),当用户单击基本域URL (customer.nl)应用程序上的“login”时,您将用户直接发送到SPA,指向登录起始端点(例如:- https://app.mydomain.com/login 1),并让子域URL应用程序启动实际的登录流。

欲知更多有关上述资料,请参阅以下连结:

https://community.auth0.com/t/log-in-from-different-subdomain-produces-state-error/19116

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72542926

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档