我引用了论坛中的其他链接,下面的代码可以运行并获取特定 upn 的安全组
private List<string> GetGroups(string userName)
{
List<string> result = new List<string>();
WindowsIdentity wi = new WindowsIdentity(userName);
foreach (IdentityReference group in wi.Groups)
{
try
{
result.Add(group.Translate(typeof(NTAccount)).ToString());
}
catch (Exception ex) { }
}
result.Sort();
return result;
}
但是相同的代码不适用于 Azure。因此,我尝试了下面的代码,该代码有效,但我没有找到读取当前用户拥有的安全组名称的方法:
var displayName = ClaimsPrincipal.Current.FindFirst(ClaimTypes.Name).Value ;
var upn = ClaimsPrincipal.Current.FindFirst(ClaimTypes.Upn).Value;
最佳答案
您问题中的代码是指使用 Windows 集成身份验证 (WIA) 进行身份验证的用户。使用 Azure AD 时,通常使用高于网络层运行的 OpenID Connect 等身份验证协议(protocol)通过公共(public) Internet 进行身份验证。这会导致调用者身份的不同表示。 请引用http://blogs.technet.com/b/ad/archive/2014/12/18/azure-active-directory-now-with-group-claims-and-application-roles.aspx有关在 Azure AD 中使用组的指南和有用链接。
关于c# - 如何获取Azure Active Directory中用户的安全组名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33898729/