首页 > 解决方案 > 即使在多租户应用获得管理员同意后,Azure AD 用户登录应用也会失败

问题描述

我在 azure 门户应用程序注册中注册了一个示例多租户应用程序,需要某些权限才能访问 Outlook 邮件。我还有一个 SAAS 应用程序,它使用此应用程序并请求用户提供 oauth 令牌以使用 Outlook 阅读和发送电子邮件。

有一组用户想要使用我的应用程序在 SAAS 应用程序中配置电子邮件的租户。但是租户中的用户没有管理员权限来同意该应用程序。根据MS 文档,管理员必须使用 v2-permissions-and-consent 同意应用程序

管理员已使用以下 URL 同意该应用程序:

https://login.microsoftonline.com/ {租户 ID}/v2.0/adminconsent?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxb&state=12345&redirect_uri=https://c9713e1c5859.ngrok.io/auth/outlook/callback&scope=https://outlook.office .com/User.Read https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send&response_type=code

管理员同意的权限: 同意的权限

即使在管理员同意应用程序请求的所有权限并将用户添加到 Azure AD 中配置的企业应用程序后,用户在尝试登录应用程序时也会看到批准提示。

向用户显示批准提示: 批准提示

理想情况下,一旦应用程序在 Azure AD 企业应用程序中获得批准,租户中的所有其他用户都应该能够在没有任何同意要求的情况下使用该应用程序。

用户用于登录的 oauth URL 是

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&redirect_uri=https%3A%2F%2Fc9713e1c5859.ngrok.io%2Fauth%2Foutlook%2Fcallback&response_type=code&scope=offline_access+https%3A% 2F%2Foutlook.office.com%2FUser.Read+https%3A%2F%2Foutlook.office.com%2FIMAP.AccessAsUser.All+https%3A%2F%2Foutlook.office.com%2FSMTP.Send&state=5bfc1a7683bfa19468e7d4d67fc6893e5a00f93efe31ca51

谁能帮我理解我在这里缺少什么?

标签: azureoauth-2.0outlookazure-active-directory

解决方案


应征得目标租户管理员同意,然后使用目标租户登录。

在下面的 url 中,你应该用错了 {tenant ID},它应该是目标租户 ID。不是您的应用所在的租户 ID。

https://login.microsoftonline.com/{tenant ID}/v2.0/adminconsent?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxb&state=12345&redirect_uri=https://c9713e1c5859.ngrok.io/auth/outlook/callback&scope=https://outlook.office.com/User.Read https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send&response_type=code

我已经测试过了,然后重现了你的问题。如果您需要进一步的帮助,请告诉我。


推荐阅读