2015-09-15 32 views
1

過期密碼(S)我有以下Python代碼對圖形API更改使用Azure的圖形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,但這樣做,我需要一個有效的令牌(打個補丁請求文件中所提及的端點),因爲我不能登錄,我沒有一個。

使用Azure圖形API在期滿時更改用戶密碼的正確方法是什麼?

回答

2

你不能。

至少不與Resource Owner Password Credentials Grantgrant_type=password)流動,在你只有最終用戶的憑據(但實際上,也有極少數情況下,這種流動是一個不錯的選擇 - 看到更多this answerthis answer)。

需要將用戶定向到Azure AD的Web界面(在瀏覽器/ Web視圖中)以驗證並更改其密碼。

+0

非常感謝所有的信息,這是有道理的。 – saps