首页 > 解决方案 > 多租户和 IdentityServer 4 和 Angular 和 oidc-client

问题描述

我们正在使用 Angular 6 开发一个多租户应用程序。每个租户使用他们的子域访问应用程序,比如client1.app.comclient2.app.com等等。

出于身份验证目的,我们使用 IdentityServer 4。我们遵循的步骤类似于以下提到的步骤:https ://identityserver4.readthedocs.io/en/release/quickstarts/7_javascript_client.html 。

一切正常 - 我们坚持的一点是我们如何redirect_uri在 Angular 客户端应用程序中指定 。

如您所知,redirect-uriIdentity Server 使用它来返回身份验证结果和信息。根据oidc-client库,它redirect_uri是一个字符串,我们不能指定多个值。但是,在我们的案例中,基于客户端的子域,情况redirect-uri会有所不同,并且必须是动态的。

有没有人遇到过类似的情况?我忽略了什么吗?任何解决上述问题的指针都会有很大帮助。

谢谢苏希尔

标签: angularidentityserver4oidc-client-js

解决方案


您需要redirect_uri在客户端中设置从主机解析(使用window.location或您想在此处使用的任何解决方案)。然后每个租户在访问 Identity Server 时都会传递这个 URI。

在 Identity Server 端,在 Client 对象中,该RedirectUris属性是一个集合,因此您应该在其中添加所有租户的重定向 uri(也不要忘记PostLogoutRedirectUris)。


推荐阅读