java - Microsoft Graph Identity Java - 租户中不存在选定的用户帐户 'Microsoft Services'

标签 java azure microsoft-graph-api azure-ad-msal microsoft-identity-platform

我想在我的 Java 应用程序中访问用户的 Outlook 日历。为此,我尝试使用 Microsoft Graph API。

我正在关注本教程: https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-v2-java-webapp其代码在这里:https://github.com/Azure-Samples/ms-identity-java-webapp/tree/master/msal-java-webapp-sample

我在 Portal.microsoft.com 上创建了类型为任何组织目录(任何 Azure AD 目录 - Multi-Tenancy )中的帐户和个人 Microsoft 帐户(例如 Skype、Xbox)的应用

我已创建 keystore.p12 并将其复制到资源目录。

我的application.properties是:

#AAD configuration
aad.clientId=my client id
aad.authority=https://login.microsoftonline.com/my tenant id/
aad.secretKey=my secret key
aad.redirectUriSignin=https://localhost:8443/msal4jsample/secure/aad
aad.redirectUriGraph=https://localhost:8443/msal4jsample/graph/me
aad.msGraphEndpointHost=https://graph.microsoft.com/

#SSL configuration
server.port=8443
server.servlet.session.cookie.secure=true
server.ssl.key-store=classpath:keystore.p12
server.ssl.key-store-password=password
server.ssl.key-store-type=PKCS12
server.ssl.key-alias=testCert
server.ssl.key-password=password

当我运行应用程序并访问 https://localhost:8443 时,我会看到带有“登录”按钮的页面。当我单击“登录”按钮时,我会被重定向到可以在 Outlook 帐户中进行选择的页面。网址是:

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=code&response_mode=form_post&redirect_uri=https%3A%2F%2Flocalhost%3A8443%2Fmsal4jsample%2Fsecure%2Faad&client_id=ca146462-8880-424c-b629-cc7c0d0fb1b3&scope=openid+offline_access+profile&prompt=select_account&state=69a2ac0f-abac-46ad-b525-88f0b70182b7&nonce=9278f424-6858-4e22-bb13-7b13894abda7

当我选择帐户时,出现以下错误:

Selected user account does not exist in tenant 'Microsoft Services' and cannot access the application 'ca146462-8880-424c-b629-cc7c0d0fb1b3' in that tenant. The account needs to be added as an external user in the tenant first. Please use a different account.

enter image description here

我添加了重定向 URI enter image description here

为什么我会收到错误消息?

更新:

我将application.properties中的权限更改为https://login.microsoftonline.com/common ,所以现在我进入“选择帐户”页面。但是当我选择帐户时,我收到 403 Forbidden 错误。

最佳答案

403 Forbidden 是您所遵循的教程的问题。由于某些浏览器中的samesite更新,response_mode需要为query(而不是form_post)。如果您尝试再次运行该示例,它应该可以工作

关于java - Microsoft Graph Identity Java - 租户中不存在选定的用户帐户 'Microsoft Services',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61674188/

相关文章:

java - 如何保持 fragment 中的滚动位置?

azure - 如何将分析中的图表固定为 azure 门户应用程序洞察资源中的最爱

outlook - 如何使用 Microsoft Graph 获取原始消息?

node.js - MS Graph API 和 DriveItem 搜索不适用于客户端凭据流

python - Microsoft Graph API 的 "Access is denied. Check credentials and try again"

java - Java 和 PHP 应用程序的 GC 和内存行为?

java - 获取mongodb中按年份和月份的所有文档

java - testng 运行多线程吗?

azure - 如何从Azure表存储迁移到SQL Azure?

php - 从 Azure Web App 上运行的 PHP 访问 Blob 存储