2015-04-21 81 views
1

我試圖從Azure廣告中獲取訪問令牌,如下面的鏈接所述。我需要使用office 365 REST API。invalid_grant嘗試獲取訪問令牌請求時Azure AD

msdn.microsoft.com/en-us/library/azure/dn645542.aspx

授權代碼的要求是全成和我收到的代碼返回URL。但訪問令牌請求失敗,我得到的響應如下。

stdClass Object 
(
    [error] => invalid_grant 
    [error_description] => AADSTS70002: Error validating credentials. AADSTS70000: The provided access grant is invalid or malformed. 
Trace ID: baf9f98a-655d-48e1-bc30-021a7d57effa 
Correlation ID: 5030b57f-42e2-403a-ab3c-cfc970d886e2 
Timestamp: 2015-04-21 12:58:00Z 
    [error_codes] => Array 
     (
      [0] => 70002 
      [1] => 70000 
     ) 

    [timestamp] => 2015-04-21 12:58:00Z 
    [trace_id] => baf9f98a-655d-48e1-bc30-021a7d57effa 
    [correlation_id] => 5030b57f-42e2-403a-ab3c-cfc970d886e2 
    [submit_url] => 
    [context] => 
) 

下面是我的代碼:

$url = "https://login.windows.net/<tenant-id>/oauth2/token"; 
      $postUrlData = "grant_type=authorization_code&client_id=$clientId&code=$authCode&redirect_uri=$redirectUri&client_secret=$secretKey"; 
      $headers = array(
       'Content-type: application/x-www-form-urlencoded', 
       'Content-length: '. strlen($postUrlData) 
      ); 
      //echo $postUrlData;die; 
      $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_POST, true); 
      curl_setopt($ch, CURLOPT_POSTFIELDS , $postUrlData); 
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
      $result = curl_exec($ch);    
      $res = json_decode($result);    
      curl_close($ch); 

你能告訴我什麼我做錯了什麼?

+0

我對你的格式做了一些小修改,讓你的問題更加清晰。 – jurgemaister

回答

相關問題