gpt4 book ai didi

azure - 如何使用graph api更新azure ad中的用户密码

转载 作者:行者123 更新时间:2023-12-02 06:18:39 26 4
gpt4 key购买 nike

我正在使用 Microsoft graph用于更新用户密码的API。我有以下 json 请求:

{
"accountEnabled": true,
"userPrincipalName": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2753425453525442551413674a5e53424946495349464a420948494a4e445548544841530944484a" rel="noreferrer noopener nofollow">[email protected]</a>",
"passwordProfile": {
"forceChangePasswordNextSignIn": false,
"password": "<new_password>"
}
}

我称之为url https://graph.microsoft.com/v1.0/users/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="542031272021273126676014392d20313a353a203a3539317a3b3a393d37263b273b32207a373b39" rel="noreferrer noopener nofollow">[email protected]</a>使用PATCH方法。我还将不记名 token 作为授权 header 传递,但出现以下错误:

{
"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.

我已经在创建的应用程序中检查了这一点,并且该权限位于应用程序注册中

enter image description here

但我仍然收到此错误。任何人都可以帮助解决这个错误。谢谢

编辑:也在 Microsoft 中添加了权限,但仍然收到相同的错误

enter image description here

编辑2:

我有下面的代码,我可以从中获取 token :

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:

我还在用户管理员中添加了应用程序名称:

enter image description here

但是问题还是一样。

最佳答案

您正在使用 Microsoft Graph,因此您需要在 Microsoft Graph 而不是 Azure Active Directory Graph 中添加权限。 enter image description here

更新:

您正在使用的是 client credentials flow ,使用此流程时,需要Application权限,如果想要获取token来更新passwordProfile,则委托(delegate)权限 需要Directory.AccessAsUser.All,要更新用户的Application权限,最多可以添加Directory.ReadWrite.All,但是这个权限不能重置用户密码

检查permissions从最低特权到最高特权:

enter image description here

然后查看Remarks对于Directory.ReadWrite.All:

Directory.ReadWrite.All

解决方案:

要使用客户端凭据流更新 passwordProfile,请将 AD 应用的服务主体添加为 Azure AD 中的目录角色。

导航到门户中的 Azure Active Directory -> 角色和管理员 -> 用户管理员 -> 添加分配 -> 搜索您的 AD 应用程序的名称 -> 添加

然后获取token来调用API,就可以正常工作了:

enter image description here

关于azure - 如何使用graph api更新azure ad中的用户密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61004464/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com