2
votes

In attempting to authenticate with Active Directory to retrieve an access token, I followed the following steps:

1 - Created an application in Azure using the following directions (step 3): https://github.com/Azure-Samples/active-directory-java-native-headless#step-3--register-the-sample-with-your-azure-active-directory-tenant

2 - Created a "Azure Active Directory" user account with the "Data Factory Contributor" permission.

3 - Used the steps from (url below), I followed the example code to attempt to retrieve an access token: https://github.com/Azure-Samples/active-directory-java-native-headless/blob/master/src/main/java/PublicClient.java

Note: the resource I am using is... https://management.core.windows.net/

... using the following as an example: https://docs.microsoft.com/en-us/azure/data-factory/quickstart-create-data-factory-rest-api#authenticate-with-azure-ad

4 - Server is responding with the following error:

Exception in thread "main" java.util.concurrent.ExecutionException:
com.microsoft.aad.adal4j.AuthenticationException:
 {
    "error_description": "AADSTS65001: The user or administrator has not
    consented to use the application with ID '<my-app-id>' named
    '<my-app-name>'. Send an interactive authorization request for this
    user and resource.\r\nTrace ID: d0af56e6-aaa3-4d25-b23b-
    2984ed2b4400\r\nCorrelation ID: 2422cc2f-1cdd-45c5-8b7c-
    46b1eee4ffae\r\nTimestamp: 2019-03-22 04:58:16Z",

    "error": "invalid_grant"
 }

What grants are required in order to get the authentication to work?

1
Did my answer solve your issue? - Tony Ju
Yes! :-) Thank you again for taking the time to reply. - user3906977

1 Answers

0
votes

You should make an authorization request to Azure AD that includes the parameter prompt=admin_consent.

Go to a URL such as https://login.microsoftonline.com/tenant-id/oauth2/authorize?client_id=app-client-id&redirect_uri=encoded-reply-url&response_type=code&prompt=admin_consent.

Use your admin account to consent the permissions.

enter image description here

Then we can get the access token successfully.

enter image description here