如何使用图形API更新天蓝色广告中访客用户的密码?蟒蛇

时间:2020-07-22 04:45:33

标签: python azure-active-directory microsoft-graph-api change-password

我在azure活动目录中添加了一些来宾用户和成员。成员是我为其前name@tenantname.info创建的用户名的成员。来宾用户就像来自Google这样的来宾用户,因此我将其添加为name@google.com

现在,我有用于更新成员密码的代码。下面是代码:

# Getting token
r = requests.post("https://login.microsoftonline.com/" + config_data['TENANT'] + "/oauth2/token",
      data={"grant_type": "client_credentials",
            "client_secret": config_data['CLIENT_SECRET'],
            "client_id": config_data['CLIENT_ID'],
            "resource": config_data['RESOURCE']})
            
ret_body = r.json()
token = ret_body['access_token']

headers = {'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json'}

user_data = {
    "accountEnabled": True,
    "userPrincipalName": "name@tenantname.info",
    "passwordProfile": {
        "forceChangePasswordNextSignIn": False,
        "password": "<password>"
    }
}

jdata = json.dumps(user_data)

conn = http.client.HTTPSConnection('graph.microsoft.com')
conn.request("PATCH", "/v1.0/users/name@tenantname.info", jdata, headers)
response = conn.getresponse()
data = response.read()

上面的代码工作得很好,我能够更新成员的密码,但是如果我想更新访客用户的密码,则会出现以下错误:

{
    "error": {
        "code": "Request_ResourceNotFound",
        "innerError": {
            "date": "2020-07-22T04:25:18",
            "request-id": "a6edf8e1-2256-4076-acc8-440607fa6119"
        },
        "message": "Resource 'name@google.com' does not exist or one of its queried reference-property objects are not present."
    }
}

任何人都可以告诉我为更新访客用户密码而必须使用哪些其他参数。请帮忙。谢谢

应用权限的屏幕截图:

enter image description here

enter image description here

enter image description here

jwt.ms的屏幕截图

enter image description here

1 个答案:

答案 0 :(得分:1)

首先,您不能使用name@tenantname.info作为请求参数,而应该使用Object ID作为请求参数(对于来宾用户,需要对象ID。普通成员用户可以使用帐户名)

 PATCH  /v1.0/users/<your guest user Object id>

经过测试,我发现使用正确的请求参数来修改来宾用户的密码,尽管会有正确的响应,但是实际上,来宾用户的密码仍然没有被修改。因此,总而言之,您无法更改访客用户的密码。因为您的AAD实际上没有为该用户分配密码。

类似的帖子here供您参考。