簡體   English   中英

使用用戶名和密碼訪問Azure Active Directory

[英]Accessing Azure Active Directory with username and password

我有一個azure訂閱,一個具有管理員權限的AD實例。 是否可以通過Graph API訪問AD並獲取所有用戶的列表?

注意:我已經研究並發現了這個示例: https//github.com/AzureADSamples/WebApp-GraphAPI-Java

但是這需要我創建一個Java Web-App,將它添加到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();
        }


    }

這確實是可能的。 AzureAD支持OAuth資源所有者密碼憑據授予。 ADAL SDK最近添加了對它的支持( https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory/2.8.10804.1442-rc )。

但請注意,如果為帳戶啟用了多因素身份驗證,或者該帳戶已配置為聯合身份驗證到ADFS以外的IdP,則此auth方法會失敗。

維托里奧在這里有一篇很好的博客文章:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM