我创建了ASP.NET MVC应用程序并使用OpenIDConnect配置了使用Azure AD进行的身份验证。我在一个Azure AD中创建了一个用户,并在另一个具有正确权限的Azure AD中添加了相同的用户。 我将在Azure AD身份验证之后返回的声明存储在ADAL缓存中。我使用这个声明(令牌缓存)来调用各种Azure服务管理API。配置ASP.Net应用程序以支持使用Azure AD帐户的多租户
ClientCredential credential = new ClientCredential(ConfigurationManager.AppSettings["ida:ClientID"],
ConfigurationManager.AppSettings["ida:Password"]);
// initialize AuthenticationContext with the token cache of the currently signed in user, as kept in the app's EF DB
AuthenticationContext authContext = new AuthenticationContext(
string.Format(ConfigurationManager.AppSettings["ida:Authority"], organizationId), new ADALTokenCache(signedInUserUniqueName));
AuthenticationResult result = authContext.AcquireTokenSilent(ConfigurationManager.AppSettings["ida:AzureResourceManagerIdentifier"], credential,
new UserIdentifier(signedInUserUniqueName, UserIdentifierType.RequiredDisplayableId));
var token= result.AccessToken;
我已经通过在帐户/登录控制器/操作中添加以下内容来配置我的应用程序以支持多租户。
public void SignIn(string directoryName = "common")
{
// Send an OpenID Connect sign-in request.
if (!Request.IsAuthenticated)
{
HttpContext.GetOwinContext().Environment.Add("Authority", string.Format(ConfigurationManager.AppSettings["ida:Authority"] + "OAuth2/Authorize", directoryName));
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
}
现在,在成功登入,返回的权利要求中,属于其中用户最初登记在原始天青AD,因此,所用的权利要求书来调用管理API用于任何其他天青AD,在用户也被添加的那个,不起作用并且抛出异常为“获取令牌未能获得令牌”。
我在运行时将其他Azure AD的名称添加到变量“directoryName”。这一次获得的索赔对Azure AD都有效。
如何获取多租户应用程序的SSO,而无需在登录时明确提及Azure AD名称,这将为我提供可用于所有用户注册的Azure AD的声明。
请提出建议。 由于提前, 拉胡尔
愚蠢的问题:你有没有配置的应用程序是多租户? –
是的,我做到了。它被配置为多租户。 用户“[email protected]”最初位于“abcdef.onmicrosoft.com”AD中。使用相同的用户名,该用户在“xyz.onmicrosoft.com”AD中注册,标签为“Source from:Another Azure AD”。 登录Azure门户后,用户可以看到两个目录。 但是,当用户使用应用程序的Azure登录时,可能索赔只属于一个目录。这就是这个原因,对另一个目录失败。 如何使用多租户配置实现SSO。 请指导。 –