python - 管理员尚未同意使用该应用程序 - Azure AD

标签 python azure oauth-2.0 azure-active-directory azure-ad-graph-api

我正在尝试通过 Python 客户端应用程序从 Azure AD 获取 token 。我希望用户只需使用用户名和密码即可进行无缝身份验证(client_id/Secret 将嵌入到应用程序中)。我注册了我的应用程序并授予了它所有权限,并根据这篇文章点击了新门户中的“授予权限”按钮:

The user or administrator has not consented to use the application - Send an interactive authorization request for this user and resource

我正在将 http 帖子发送至:

https://login.microsoftonline.com/{tenant_id}/oauth2/token

具有以下数据:

headers = {
    "Content-Type": "application/x-www-form-urlencoded"
}

body = "resource={0}&grant_type=password&username={1}&password={2}&client_id={3}&client_secret={4}&scope=openid".format(app_id_uri,user,password,client_id,client_secret)

无论我如何尝试,我似乎都无法克服这个错误:

b'{"error":"invalid_grant","error_description":"AADSTS65001: The user or administrator has not consented to use the application with ID \'078c1175-e384-4ac7-9116-efbebda7ccc2\'. Send an interactive authorization request for this user and resource.

再说一遍,我的目标:

用户输入用户名/密码,仅输入其他内容。 App发送user/pass/client_id/client_secret,获取token。

最佳答案

根据您的评论:

The message I'm receiving says to do an interactive request but that is exactly what I'm trying to avoid because this is a python app with no web browser and I'm trying to avoid complexity.

我认为您想要构建一个守护程序应用程序或与 Azure AD 集成的仅应用程序应用程序。您可以引用https://graph.microsoft.io/en-us/docs/authorization/app_only作一般介绍。

此外,您可以利用 ADAL for Python轻松实现此功能。另外,您可以引用client_credentials_sample.py快速开始。

关于python - 管理员尚未同意使用该应用程序 - Azure AD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41421355/

相关文章:

python - python项目可以依赖特定版本的python吗?

python - 如何使用 python/matplotlib 绘制中间有空行的数据

python - 为什么不过滤(不是无,可迭代)?

Windows Azure 上托管的 asp.net mvc 3 中的 Windows 身份验证?

.net - 在 Web Api 中本地化 OAuth 消息

python - 实现常微分方程组的循环

azure - 微软动力 : Generate Refresh Token for OAuth

google-app-engine - 谷歌应用引擎 : SimpleAuth : Redirect Url On the Fly

java - Spring安全认证: migration from xml to annotations

azure - 是否可以将基于 IIS 的应用程序部署到 Service Fabric 中?