1

我有以下 Python 代码来对 Graph API 进行身份验证

import requests

def login(tenant_name, client_id, client_secret, username, password):
     url = 'https://login.windows.net/' + tenant_name + '/oauth2/token'
     payload = {
             'grant_type': 'password',
             'username': username + '@' + tenant_name,
             'password': password,
             'client_id': client_id,
             'client_secret': client_secret,
             'resource': 'https://graph.windows.net'
     }

     r = requests.post(url, data=payload)

    return r.json()

如果我有密码已过期的用户,我会收到响应(如预期的那样):

{
 'timestamp': '2015-09-15 02:59:26Z',
 'trace_id': '8abff845-6941-4867-9729-15626c23330f',
 'submit_url': None, 
 'correlation_id': '81184c06-2627-4bca-82e3-76aab7713a5f', 
 'error_description': 'AADSTS70002: Error validating credentials. AADSTS50055: Password is expired.
Trace ID: 8abff845-6941-4867-9729-15626c23330f
Correlation ID: 81184c06-2627-4bca-82e3-76aab7713a5f
Timestamp: 2015-09-15 02:59:26Z',
 'context': None,
 'error': 'user_password_expired', 
 'error_codes': [70002, 50055]
}

Graph API 提供了使用端点来重置密码,但要这样做,我需要一个有效的令牌(向文档中提到的端点发出 PATCH 请求),因为我无法登录,所以我没有。

使用 Azure Graph API 在到期时更改用户密码的正确方法是什么?

4

1 回答 1

3

你不能。

至少在资源所有者密码凭证授予( grant_type=password) 流程中没有,您只有最终用户的凭证(尽管实际上,很少有这种流程是一个不错的选择的情况——请参阅这个答案这个答案以获得更多信息) .

用户需要被定向到 Azure AD 的 Web 界面(在浏览器/Web 视图中)以进行身份​​验证和更改其密码。

于 2015-09-15T04:25:13.810 回答