小编Xav*_*erk的帖子

Azure Active Directory Graph Client 2.0

有人使用新的2.0版Azure AD Graph Client吗?

我昨天开始愚弄它但却无法让它发挥作用.将GraphConnection类标记为弃用,取而代之ActiveDirectoryClient.此外,突然之间它全部是Office 365,而我只是想在没有O365的情况下将我的试用限制在Azure Active Directory中.至少在您不想使用O365和O365 API工具时,很难找到文档.GitHub上的AD示例似乎也在更新,但代码仍在使用GraphConnection类.去搞清楚.

关于使用ActiveDirectory客户端的样本/指导并不多,所以目前使用的代码如下

public async Task<ActionResult> Index()
        {
            List<Exception> exceptions = new List<Exception>();
            ProfileViewModel model = new ProfileViewModel();
            string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
            AuthenticationContext authContext = new AuthenticationContext(SecurityConfiguration.Authority, new NaiveSessionCache(userObjectID));
            ClientCredential credential = new ClientCredential(SecurityConfiguration.ClientId, SecurityConfiguration.AppKey);

            try
            {
                var ServiceUri = new Uri(SecurityConfiguration.GraphUrl);
                ActiveDirectoryClient client = new ActiveDirectoryClient(ServiceUri, async () =>
                {
                    var result = await authContext.AcquireTokenSilentAsync(SecurityConfiguration.GraphUrl, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));

                    return result.AccessToken;
                });
                try
                {

                    var users …
Run Code Online (Sandbox Code Playgroud)

graph active-directory azure

10
推荐指数
1
解决办法
4395
查看次数

使用图形 api 在 Azure 活动目录组中搜索用户

我希望在我的 asp.net mvc 5 应用程序中具有某种具有自动完成功能的人员选择器功能,以搜索特定 Azure AD 组中的用户。这是一个演示“待办事项应用程序”,允许将待办事项分配给属于组成员的用户。

我直接尝试了 Graph API 和 Azure Graph Client 库,但似乎没有找到实现我想要的方法。图 api 允许获取组的成员,但添加过滤器“startswith”失败,因为在添加过滤器时,api 仅返回不包含例如 DisplayName 属性的目录对象......客户端库也没有太大帮助除了批处理功能提供了一种方法但有很多开销......然后我必须获得用户的过滤结果集,而不管组成员身份(使用 api 中的用户列表内容),组的所有成员,然后使用 Linq 找出正确的结果集......对于开发/测试来说可以正常工作,但在有几百个用户的生产中这将是疯狂的......

任何想法或建议将不胜感激。谢谢!

编辑

在我从客户端 Javascript 调用以搜索用户的代码下方;

  • AccessGroupId 是用于授权用户的 Azure AD 组。只有该组的成员才能访问我在自定义 OWin 中间件中处理的 Web 应用程序
  • 该方法旨在用于查找该组中的用户

代码工作正常,如下所示,只是没有应用过滤,这是输入参数 pre(来自 ui 中的文本框)的意图。我得到了访问组的所有成员。

public async Task<JsonResult> FindUser(string pre) 
{
    string AccessGroupId = ConfigurationManager.AppSettings["AccessGroupId"];
    AuthenticationContext authCtx = new AuthenticationContext(String.Format(CultureInfo.InvariantCulture, "{0}/{1}", SecurityConfiguration.LoginUrl, SecurityConfiguration.Tenant));
    ClientCredential credential = new ClientCredential(SecurityConfiguration.ClientId, SecurityConfiguration.AppKey);
    AuthenticationResult assertionCredential = await authCtx.AcquireTokenAsync(SecurityConfiguration.GraphUrl, credential);
    var accessToken = assertionCredential.AccessToken;

    var graphUrl …
Run Code Online (Sandbox Code Playgroud)

c# search graph active-directory azure

5
推荐指数
1
解决办法
8632
查看次数

标签 统计

active-directory ×2

azure ×2

graph ×2

c# ×1

search ×1