1

I've created native app in Azure AD. I have piece of code that acquire token using user from Azure AD user(which is email)/password credentials:

public static void main(String[] args) throws MalformedURLException, ExecutionException, URISyntaxException {

    String clientId = "myAppIdInAzureId";
    String resourceUrl = "https://graph.windows.net";
    String authorityUrl = "https://login.microsoftonline.com/xxxxxxxxxxxxxxxxxxxxxxxxxxx/oauth2/authorize";
    String email = "my.email@post.com";
    String password = "password";
    ExecutorService executorService = Executors.newFixedThreadPool(4);
    Optional<UserInfo> userInfo = Optional.empty();

    try {

        AuthenticationContext authContext = new AuthenticationContext(authorityUrl, false, executorService);
        Future<AuthenticationResult> future = authContext.acquireToken(resourceUrl, clientId, email, password, null);

        AuthenticationResult result = future.get();
        userInfo = Optional.of(result.getUserInfo());

    } catch (InterruptedException | MalformedURLException | ExecutionException e) {
        System.out.println("Azure AD Authentication Exception using {" + email + "} email address, exception:" + e);
    }

    if (userInfo.isPresent()) {
        System.out.println(userInfo.get().getGivenName());
        System.out.println(userInfo.get().getFamilyName());
    }
}

Later I obtain userInfo object and get desired data, First and Last name.

It was working locally, but after deploying to server there is error:

Azure AD Authentication Exception using {my.email@post.com} email address, exception:java.util.concurrent.ExecutionException: com.microsoft.aad.adal4j.AdalClaimsChallengeException: {"error_description":"AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access …

So the question is how to use multi-factor authentication using adal4j? Any ideas? I don't want to use any page redirection.

I know that even if AADSTS50076 error occurs email/password combination is correct(otherwise there is another, different error) but I can't get userInfo object with AADSTS50076

Best Regards

piotrassss
  • 205
  • 1
  • 4
  • 10

0 Answers0