![](/img/trans.png)
[英].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.