c# - 如何获取Azure Active Directory中用户的安全组名称

标签 c# azure active-directory wif azure-active-directory

我引用了论坛中的其他链接,下面的代码可以运行并获取特定 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/

相关文章:

c# - 为什么 Principal.IsMemberOf() 对某些组返回假阴性?

c# - DateTime.TryParse 成功解析了一些数字

c# - Json解析日期时间格式

c# - TaskAwaiter 无法从用法推断

c# - 在 Azure 函数中使用 RestSharp 调用 HTTPS 会给出 "The SSL connection could not be established"

azure - 宇宙数据库 : Call a stored procedure from another stored procedure or trigger

c# - 如何从 AD DirectoryEntry 获取 DOMAIN\USER?

azure - 如何在 Powershell 中向 Azure AAD 应用程序授予管理员同意?

c# - 如何生成不寻常但数学上有效的 RSA key ?

azure - 辅助角色不创建模型对象?