【问题标题】:LDAP DirectorySearcher for Office 365 Active DirectoryOffice 365 Active Directory 的 LDAP DirectorySearcher
【发布时间】:2016-08-02 17:05:38
【问题描述】:

如果我的服务器中有一个 Active Directory 设置,其域是“mydomain.com”,我将为此创建 LDAP DirectorySearcher,如下所示。

string domainPath = "LDAP://mydomain.com";
DirectoryEntry entry = new DirectoryEntry(domainPath, "userName", "password");
DirectorySearcher searcher = new DirectorySearcher(entry);

如果我想为我的 Office 365 Active Directory 创建 DirectorySearcher,domainPath 是什么?

P.S : 我已使用“AzureADSync”将服务器的 Active Directory 与 Office 365 同步

【问题讨论】:

    标签: active-directory office365 azure-active-directory directoryservices


    【解决方案1】:

    LDAP 仅适用于本地 Active Directory。

    对于 Azure Active Directory,您需要使用图形 API(Microsoft Graph 或 Azure Active Directory Graph。有关如何在其中一个和另一个之间进行选择的信息,请参阅 this link)

    您需要注册您的应用程序,根据您想要执行的操作设置正确的权限,并拥有类似于此 sn-p 的代码:

    注意:这个特殊的 sn-p 返回目录中的所有用户:

    var authority = "https://login.microsoftonline.com/";
    var resource = "https://graph.windows.net/";
    
    var tenant = "mydomain.com";
    var clientId = <YourClientID>;
    var redirectUri = <YourRedirectUri>;
    
    var ctx = new AuthenticationContext(authority + tenant);
    
    var graphUri = resource + tenant;
    var client = new ActiveDirectoryClient(new Uri(graphUri), 
        async () => { 
            var token = await ctx.AcquireTokenAsync(resource, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Always)); 
            return token.AccessToken;
        });
    
    
    var users = await client.Users.ExecuteAsync();
    users.CurrentPage.Select(u => u.DisplayName).Dump();
    

    这里是a link to Azure AD Graph samples。其中包含有关应用注册、设置权限以及如何从不同平台/场景查询图表的说明。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-15
      相关资源
      最近更新 更多