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