我創建了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。 請指導。 –