[英].Net Core Azure AD Cloud how to get logged in user and access their Azure AD Security Groups to determine if they are in a group
[英]Determine if a logged in user is a member of an AD group, in a web app deployed to Azure
我在部署到Azure的Web應用程序中使用Windows Identity Framework進行身份驗證。 在本地運行應用程序時,可以使用PrincipalContext查看用戶是否在組中:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "DOMAIN");
// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, username);
// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "GROUP-NAME");
if (user != null)
{
// check if user is member of that group
return user.IsMemberOf(group);
}
這在本地有效,但在部署到Azure的應用程序中無效。 我不確定現在如何檢查此信息。 我已經看到LDAP協議在Azure中不受支持,因此這就是它不起作用的原因,但是我不確定現在嘗試完成此操作的正確方法。 我已經閱讀了一些有關組聲明,應用程序角色和Azure Graph API的信息,但是它們看起來像是過大了,或者不是我應該遵循的方向。 有什么幫助嗎?
正如您已經發現的那樣,該方法在Azure AD中不起作用-您的應用程序未在Intranet中運行,因此無法進行這些調用。 對此的標准解決方案是確保Azure AD在登錄時發送的令牌中包括組,請參見此示例 。
您需要牢記各種注意點-主要的一點是,使用WIF會迫使您依賴WSFederation,如果您有太多的組,這就不方便了:Azure AD通過期望您避免發行大型令牌回調到Azure AD Graph API並在事后檢索組,但是該操作需要更現代的協議,如OpenID Connect(如我鏈接到的示例所示)。
另一個挑戰是,出於安全原因,令牌中的組由其SID而不是其名稱表示-因此,您需要知道要針對其進行驗證的SIDS(或調用圖來檢索其名稱)。
高溫超導
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.