如何使用图表 API. 更新 Azure 广告中来宾用户的密码? Python

How to update password for guest users in azure ad using graph API.? Python

我在 Azure 活动目录中添加了一些来宾用户和成员。成员是那些我为 ex 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."
    }
}

任何人都可以告诉我必须使用哪些附加参数才能更新来宾用户的密码。请帮忙。谢谢

应用权限截图:

jwt.ms

的截图

首先,不能使用name@tenantname.info作为请求参数,应该使用Object ID作为请求参数(guest用户需要object id,普通会员用户可以使用account名字)。

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

经过我的测试发现,使用正确的请求参数修改guest用户的密码,虽然会有正确的响应,但实际上guest用户的密码还是没有被修改。因此,综上所述,您无法更改来宾用户的密码。因为你的 AAD 实际上并没有为这个用户分配密码。

类似post供大家参考。