【问题标题】:How to update the password of user in azure ad using graph api如何使用图形 api 在 azure ad 中更新用户的密码
【发布时间】: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


    【解决方案1】:

    您使用的是Microsoft Graph,因此您需要在Microsoft Graph而不是Azure Active Directory Graph中添加权限。

    更新:

    你使用的是client credentials flow,在使用这个流程时,需要Application permission,如果你想获取token来更新passwordProfile委托权限 @987654337需要@,用Application permission更新用户,我们最多可以添加Directory.ReadWrite.All,但是这个权限不能reset user passwords

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

    然后查看Remarks for Directory.ReadWrite.All

    解决方案:

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

    导航到门户中的Azure Active Directory -> Roles and administrators -> User administrator -> Add assignments -> 搜索您的 AD 应用的名称 -> Add

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

    【讨论】:

    • 谢谢。我也添加了,但我仍然收到此错误
    • @SAndrew 你是如何获得令牌的?
    • 我已经编辑了这个问题。请看一下edit2。谢谢
    • 我已经检查了所有的权限,只有user.ManageIdentites.All 丢失了。我已要求我的 IT 人员添加此内容,然后我将在此处进行测试和更新。谢谢
    • 您可以将用户管理员角色等分配给应用程序。这应该允许通过客户端凭据流重置密码。您可以通过角色和管理员选项卡来做到这一点。
    猜你喜欢
    • 1970-01-01
    • 2018-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-19
    • 1970-01-01
    相关资源
    最近更新 更多