【问题标题】:Microsoft Graph Identity Java - Selected user account does not exist in tenant 'Microsoft Services'Microsoft Graph Identity Java - 租户“Microsoft 服务”中不存在所选用户帐户
【发布时间】:2020-08-23 17:12:47
【问题描述】:

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

我正在学习本教程: https://docs.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 上创建了应用程序,类型为 Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. 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

当我选择一个帐户时,我收到以下错误:

租户“Microsoft 服务”中不存在所选用户帐户 并且无法访问应用程序 该租户中的“ca146462-8880-424c-b629-cc7c0d0fb1b3”。账户 需要先在租户中添加为外部用户。请用 另一个帐户。

我添加了重定向 URI

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

更新:

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

【问题讨论】:

  • 由于您尝试登录您的 Azure AD 租户,该 Outlook 帐户是否在该 Azure AD 租户中?如果您打算让您的应用成为多租户,您的权限应该是https://login.microsoftonline.com/common/v2.0
  • @juunas Outlook 帐户不在该 Azure AD 租户中。我想访问任何用户的日历。我将 application.properties 中的权限更改为:https://login.microsoftonline.com/common/v2.0/my-tenant-id/,但随后在浏览器中出现错误:未找到网址的网页:login.microsoftonline.com/common/v2.0......
  • 不要在此处添加您的租户 ID。将权限设置为https://login.microsoftonline.com/common/v2.0
  • @juunas 我从权限中删除了租户 ID,但我得到:https://login.microsoftonline.com/common/v2.0/oauth2/v2.0/authorize?response_type=code&response_mode=form_post&redirect_uri=...
  • 这是您所遵循的教程的问题。由于某些浏览器的同站更新,response_mode 需要查询(而不是 form_post)。如果您尝试再次运行该示例,它应该可以工作。

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    复制juunas提到的cmets中的解决方案:

    如果应用是多租户的,只需使用“commonhttps://login.microsoftonline.com/common/oauth2/v2.0/authorize

    【讨论】:

    • 这也适用于标准 Microsoft 帐户。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多