简体   繁体   English

绕过 Azure B2C 重定向 uri 限制

[英]Bypass Azure B2C redirect uri limit

Background背景

When configuring authentication using Azure B2C, you register your app within Azure and specify return Uri's that Azure are allowed to redirect back to.使用 Azure B2C 配置身份验证时,您在 Azure 中注册您的应用程序并指定允许 Azure 重定向回的返回 Uri。 These redirect Uri's have a max limit of 256 uri's .这些重定向 Uri 的最大限制为 256 个 uri My client that I implement this for have multiple subdomains and top domains that are directed to the same site with different cultures (using Optimizely CMS).我为其实现此功能的客户有多个子域和顶级域,这些子域和顶级域指向具有不同文化的同一站点(使用 Optimizely CMS)。 This means that they will break the limit of 256 Uri's if all of these are registered in the app.这意味着如果所有这些都在应用程序中注册,他们将突破 256 个 Uri 的限制。 Also, it would be a tedious job to configure every single Uri in the app registration.此外,在应用程序注册中配置每个 Uri 将是一项繁琐的工作。 Thus, I am trying to figure out the best approach to solve this without breaking best practices.因此,我试图在不破坏最佳实践的情况下找出解决此问题的最佳方法。

Expectation期待

I am hoping to find a solution that would allow me to only have to register one or a hand full redirect Uri's in Azure app registration, but still being able to use multiple different subdomains and top domains to initiate an authentication flow.我希望找到一种解决方案,让我只需要在 Azure 应用程序注册中注册一个或一个完整的重定向 Uri,但仍然能够使用多个不同的子域和顶级域来启动身份验证流程。

Approaches方法

State parameter Using the state parameter you are able to pass custom data throughout the entire authentication flow.状态参数使用状态参数,您可以在整个身份验证流程中传递自定义数据。 In this way you can pass your own redirect Uri.通过这种方式,您可以传递自己的重定向 Uri。 However, this seems to only works for paths and subdomains, but not with top domains.但是,这似乎只适用于路径和子域,而不适用于顶级域。 If I pass a different top domain then the one I am initiating the authentication, I end up in a redirect loop.如果我传递的顶级域与我正在启动身份验证的顶级域不同,我最终会陷入重定向循环。 My guess is that it is due to the cookie not being able to be set since it is cross domain.我的猜测是,这是由于 cookie 无法设置,因为它是跨域的。

Wild card Uri's By defining Uri's using wild cards it is possible to minimize the amount of domains registered.通配符 Uri's通过使用通配符定义 Uri's,可以最大限度地减少注册域的数量。 But this approach is not recommended due to security implications.但由于安全隐患,不推荐使用这种方法。

Multiple app registrations One approach could be to configure the OpenIdConnect solution to handle multiple app registration.多个应用注册一种方法是配置 OpenIdConnect 解决方案来处理多个应用注册。 Thus, that a group of Uri's are connected to one app registration, and another group to another app.因此,一组 Uri 连接到一个应用程序注册,另一组连接到另一个应用程序。 And depending of the request url the correct app registration is used to initiate an authentication request.并且根据请求 url,使用正确的应用程序注册来发起身份验证请求。 This sounds to me to as quite good solution, but it does not minimize the workload needed to add all redirect Uri's and maintaining them.这对我来说是一个很好的解决方案,但它并没有减少添加所有重定向 Uri 和维护它们所需的工作量。

Wrap the authentication flow in a custom solution In this approach only one specific top domain (domain A) would be used to initiate an authentication towards Azure B2C.在自定义解决方案中包装身份验证流程在这种方法中,只有一个特定的顶级域(域 A)将用于启动对 Azure B2C 的身份验证。 A user that want to logon from domain B would click a login button, the button redirects the user to domain A where the authentication is initiated towards Azure B2C.想要从域 B 登录的用户将单击登录按钮,该按钮会将用户重定向到域 A,在域 A 中启动对 Azure B2C 的身份验证。 When the user is authenticated the user is redirected back to domain A where a token (or similar) is created and then sent back to domain B. When the token reaches domain B this is saved in the session and the user is then considered authenticated.当用户通过身份验证时,用户将被重定向回域 A,在域 A 中创建令牌(或类似的),然后发送回域 B。当令牌到达域 B 时,它被保存在会话中,然后用户被认为已通过身份验证。 I don't like this approach.我不喜欢这种方法。 Feels like the entire purpose of Azure B2C is lost if this approach is used, and also this would add more complexity and attack vectors.如果使用这种方法,感觉 Azure B2C 的全部目的都会丢失,而且这会增加更多的复杂性和攻击向量。

Questions问题

Is there any of these approaches that you would recommend?您会推荐这些方法吗? Is there any other approaches I've missed that might work?我错过了其他可能有效的方法吗?

As a former Episerver/Optimizely developer I have to say that I would reconsider your architectural approach if you are surpassing 256 domains/subdomains.作为前 Episerver/Optimizely 开发人员,我不得不说,如果您超过 256 个域/子域,我会重新考虑您的架构方法。 Are you using a different subdomain for each language version?您是否为每个语言版本使用不同的子域?

Anyhow, if you insist on your approach, I would recommend registering each top level domain as a single Redirect Uri and then handling the subdomain/path in the state.无论如何,如果您坚持您的方法,我建议将每个顶级域注册为单个重定向 Uri,然后处理状态中的子域/路径。 That could mean that authentication is handled under www.domain.com and then using state you are redirected back to en.domain.com or de.domain.com .这可能意味着身份验证是在www.domain.com下处理的,然后使用状态将您重定向回en.domain.comde.domain.com This will probably require implementing a custom controller that handles the authentication flow, state and setting cookie domains correctly.这可能需要实现一个自定义控制器来正确处理身份验证流程、状态和设置 cookie 域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM