Access to Azure Active Directory with username and password

I have an azure subscription, an AD instance with admin rights. Is it possible to access AD through the Graph API and get a list of all users?

Note. I already researched and came across this example: https://github.com/AzureADSamples/WebApp-GraphAPI-Java

But for this I need to create a Java Java application, add it to the azure application, get the client ID and privacy, and then authenticate.

Is there no way to authenticate (get an access token) by writing a simple java command line program using the ADAl4J library and providing the AD username and password as credentials?

For example:

 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();
        }


    }

      

+3


source to share


1 answer


It really is possible. AzureAD supports the Credential Credential grant for the OAuth resource owner. The ADAL SDK recently added support ( https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory/2.8.10804.1442-rc ).

Note, however, that this auth method fails if multi-factor authentication is enabled for the account, or if the account is configured for federated authentication on a non-ADFS IdP.



Vittorio has a nice blog post about this here:

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

+2


source







All Articles