如何使用graph api更新azure ad中用户的密码
我正在使用Microsoft如何使用graph api更新azure ad中用户的密码,azure,api,graph,passwords,azure-active-directory,Azure,Api,Graph,Passwords,Azure Active Directory,我正在使用MicrosoftgraphAPI更新用户的密码。我有以下要求: { "accountEnabled": true, "userPrincipalName": "testuser34@mytenantname.onmicrosoft.com", "passwordProfile": { "forceChangePasswordNextSignIn": false, "password": "<new_password>
graph
API更新用户的密码。我有以下要求:
{
"accountEnabled": true,
"userPrincipalName": "testuser34@mytenantname.onmicrosoft.com",
"passwordProfile": {
"forceChangePasswordNextSignIn": false,
"password": "<new_password>"
}
}
错误显示权限不足
。根据这一点,我下面说:
更新passwordProfile属性时,需要以下权限: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()))
data={
“授予类型”:“客户端凭据”,
“客户机密”:,
“客户id”:,
“资源”:https://graph.microsoft.com"
}
r=请求。post(“https://login.microsoftonline.com//oauth2/token“,数据)
如果r.status_code==200:
ret_body=r.json()
token=ret_body['access_token']
其他:
log.error(“无法从oauth{},{}获取令牌”。格式(r.status_代码,r.json())
Edit3:
我还在user administrator中添加了应用程序名称:
但是问题仍然是一样的。您使用的是
Microsoft Graph
,因此您需要在Microsoft Graph
中添加权限,而不是Azure Active Directory Graph
。
更新:
您正在使用的是,当使用此流时,需要应用程序权限
,如果您希望获得令牌以更新密码配置文件
,则需要委托权限目录.accessUser.All
,以使用应用程序权限
更新用户,我们最多只能添加目录.ReadWrite.All
,但此权限不能重置用户密码
检查从最低到最高特权:
然后查看for目录。ReadWrite.All
:
解决方案:
要使用客户端凭据流更新密码配置文件
,请在Azure AD中将AD应用程序的服务主体添加为目录角色
导航到门户中的Azure Active Directory
,角色和管理员
->用户管理员
->添加工作分配
->搜索广告应用程序的名称->添加
然后获取令牌以调用API,它可以正常工作:
谢谢。我也添加了这个,但我仍然得到这个error@SAndrew你是怎么得到令牌的?我已经编辑了这个问题。请看一下edit2。谢谢我已经检查了所有权限,只有user.manageidenties。所有的都丢失了。我已经要求我的IT人员添加这个,然后我将在这里进行测试和更新。感谢您可以为应用程序分配用户管理员角色等。这应该允许通过客户端凭据流重置密码。您可以通过“角色和管理员”选项卡执行此操作。
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()))