使用 Azure Graph API 更改过期密码
Changing expired password(s) using Azure Graph API
我有以下 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]
}
图表 API 为 reset a password 提供了一个端点,但为此,我需要一个有效的令牌(向文档中提到的端点发出 PATCH 请求),因为我不能登录不了,我没有
使用 Azure Graph API 更改到期用户密码的正确方法是什么?
你不能。
至少不与 Resource Owner Password Credentials Grant (grant_type=password
) flow, where you only have the end-user's credentials (though really, there are very few cases where this flow is a good choice--see this answer and 更多)。
用户需要被定向到 Azure AD 的 Web 界面(在 browser/web 视图中)以验证和更改他们的密码。
我有以下 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]
}
图表 API 为 reset a password 提供了一个端点,但为此,我需要一个有效的令牌(向文档中提到的端点发出 PATCH 请求),因为我不能登录不了,我没有
使用 Azure Graph API 更改到期用户密码的正确方法是什么?
你不能。
至少不与 Resource Owner Password Credentials Grant (grant_type=password
) flow, where you only have the end-user's credentials (though really, there are very few cases where this flow is a good choice--see this answer and
用户需要被定向到 Azure AD 的 Web 界面(在 browser/web 视图中)以验证和更改他们的密码。