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

标签 java azure api

我正在关注this document并看到以下问题。

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

我已按照以下步骤操作:

  1. 将应用注册为公共(public)客户端
  2. 更新了 list 以将allowPublicClient属性设置为true
  3. 设置用户读取权限
  4. 还获得了授予/撤销管理员同意

我引用了多篇文章来解决这个问题;但没有一个起作用。任何指示都会有所帮助。这是我正在使用的代码:

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

最佳答案

首先,您需要是租户的管理员(如果您不是租户管理员,则无法授予管理员权限),可以按照 here 设置用户角色流程。

然后按照以下流程向应用程序授予管理员同意:

  1. 登录https://portal.azure.com作为租户管理员。
  2. 在以下位置打开您的应用程序注册。
  3. 转到“设置”,然后选择所需的权限。
  4. 按下授予权限按钮。

enter image description here

根据你的问题,我使用了 ROPC flow 测试以获取访问 token 。

enter image description here

解析 token 以查看user.read的范围。 enter image description here

最后,要获取用户信息,请访问https://graph.microsoft.com/v1.0/me Api。 enter image description here

关于java - AADSTS65001 : The user or administrator has not consented to use the application with ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62494916/

相关文章:

ruby - Ruby 中是否有与查找相反的方法?

java - 向下转换为间接子类不起作用?

java - Java 中的 Chromedriver 不可执行

azure - 术语 'Get-AzureRmDataFactoryV2' 未被识别为 cmdlet 的名称

javascript - 使用 $cordovaOauth 使用 Facebook 登录

python - 上传超过 5000 个联系人到 Telegram

java - 线程中出现异常 "main"java.lang.NullPointerException

java - 在eclipse中将项目转换为maven后的目录结构

azure - 使用 Bicep/YAML 禁用部署逻辑应用程序(标准)工作流

python - 在 Python 中创建 Azure key 保管库