简体   繁体   中英

AADSTS65001: The user or administrator has not consented to use the application with ID

I am following this document and seeing the following issue.

ERROR com.microsoft.aad.msal4j.PublicClientApplication - [Correlation ID: 6ed3f887-f7a7-4201-ba9c-6587d8510ef8] Execution of class com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier failed.
com.microsoft.aad.msal4j.MsalInteractionRequiredException: AADSTS65001: The user or administrator has not consented to use the application with ID 'ab8dd9d6-d79b-454d-9c40-236a74cfe698' named 'AzureTestApp01'. Send an interactive authorization request for this user and resource.
Trace ID: 0eb3ee9e-b1c1-43e8-90b3-2a1a70b71100
Correlation ID: 6ed3f887-f7a7-4201-ba9c-6587d8510ef8
Timestamp: 2020-06-19 22:32:40Z

I have followed the steps below:

  1. Registered the app as Public client
  2. updated Manifest to set allowPublicClient property to true
  3. set the User.Read permission
  4. also given Grant/revoke admin consent

I have referred multiple articles to resolve this; but none worked. Any pointers will be helpful. This is the code I am using:

PublicClientApplication pca = PublicClientApplication.builder(APP_ID).authority(AUTHORITY).build();
String scopes = "User.Read";
UserNamePasswordParameters parameters = UserNamePasswordParameters.builder(Collections.singleton(scopes),userName,password.toCharArray()).build();
IAuthenticationResult result = pca.acquireToken(parameters).get();

First, you need to be the administrator of the tenant (if you are not a tenant administrator, you cannot give the administrator permission), you can set up user roles according to here process.

Then follow this process to grant administrator consent to the app:

  1. Log in to https://portal.azure.com as a tenant administrator.
  2. Open the registration of your application in the following location.
  3. Go to settings and then the required permissions.
  4. Press the grant permission button.

在此处输入图像描述

Based on your question, I used the ROPC flow test to get the access token.

在此处输入图像描述

Parse the token to see the scope of user.read . 在此处输入图像描述

Finally, to obtain user information, visit https://graph.microsoft.com/v1.0/me Api. 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM