【发布时间】:2020-07-15 04:26:14
【问题描述】:
我正在使用 Microsoft graph API 来更新用户的密码。我有以下 json 请求:
{
"accountEnabled": true,
"userPrincipalName": "testuser34@mytenantname.onmicrosoft.com",
"passwordProfile": {
"forceChangePasswordNextSignIn": false,
"password": "<new_password>"
}
}
我使用PATCH 方法调用此url https://graph.microsoft.com/v1.0/users/testuser34@mytenantname.onmicrosoft.com。我还将不记名令牌作为授权标头传递,但出现以下错误:
{
"error": {
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.",
"innerError": {
"request-id": "12781f2a-0cdd-449d-94d7-aae1440a7559",
"date": "2020-04-03T02:52:57"
}
}
}
错误提示 Insufficient privileges。根据我关注的page,它说:
When updating the passwordProfile property, the following permission is required: Directory.AccessAsUser.All.
我已经在创建的应用中检查了这个,并且这个权限在应用注册中
但我仍然收到此错误。任何人都可以帮助解决此错误。谢谢
编辑:在 Microsoft 中也添加了权限,但仍然出现相同的错误
编辑 2:
我有以下获取令牌的代码:
data = {
"grant_type": "client_credentials",
"client_secret": <client_secret>,
"client_id": <client_id>,
"resource": "https://graph.microsoft.com"
}
r = requests.post("https://login.microsoftonline.com/<tennant_id>/oauth2/token", data)
if r.status_code == 200:
ret_body = r.json()
token = ret_body['access_token']
else:
log.error("Unable to get token from oauth {}, {}".format(r.status_code, r.json()))
编辑3:
我还在用户管理员中添加了应用名称:
但问题还是一样。
【问题讨论】:
标签: azure api graph passwords azure-active-directory