使用用户名和密码访问Azure Active Directory

4
我有一个Azure订阅,一个具有管理员权限的AD实例。是否可以通过Graph API访问AD并获取所有用户的列表?
注意:我已经进行了研究,并找到了这个示例: https://github.com/AzureADSamples/WebApp-GraphAPI-Java 但是这需要我创建一个Java Web应用程序,将其添加到Azure应用程序中,获取客户端ID和密钥,然后进行身份验证。
难道没有一种方法可以通过使用ADAl4J库编写简单的命令行Java程序进行身份验证(获取访问令牌),并将AD用户名和密码作为凭据提供吗?
例如:
 public static void main(String srgs[])
    {
        String authority = "https://login.windows.net/";
        String tenant = "mytenant.onmicrosoft.com" ;


        AuthenticationContext context = null;
        AuthenticationResult result = null;
        ExecutorService service = null;
        try {
            service = Executors.newFixedThreadPool(1);
            context = new AuthenticationContext(authority + tenant + "/", true,
                    service);
            Future<AuthenticationResult> future = context.acquireToken(
                    "https://graph.windows.net", new ClientCredential("AD-USERNAME",
                    "AD-PASSWORD"), null);
            result = future.get();
        } catch (Exception e) {
             e.getCause();
        } finally {
            service.shutdown();
        }


    }
1个回答

3

的确是有可能的。AzureAD支持OAuth资源所有者密码凭据授权。ADAL SDK最近已经为其添加了支持(https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory/2.8.10804.1442-rc)。

请注意,当启用帐户的多因素身份验证或将帐户配置为联合身份验证到除ADFS以外的IdP时,此身份验证方法会失败。

Vittorio在这里发表了一篇很好的博客文章:

http://www.cloudidentity.com/blog/2014/07/08/using-adal-net-to-authenticate-users-via-usernamepassword/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接