2017-06-06 104 views
1

我們正在從Guzzle3移動到Guzzle6。我編寫了一個過程來驗證和訪問在Guzzle3中正常工作的Azure Management API。但是,我無法弄清楚如何在Guzzle6中使用它。其目的是獲取訪問令牌,然後在Azure Management API的後續請求中使用該令牌。使用Guzzle6獲取Azure令牌時出現問題(錯誤:AADSTS90014)

原始代碼:

$client = new Guzzle\Http\Client(); 
$request = $client->post("https://login.microsoftonline.com/{$tenant_id}/oauth2/token", 
    Array(
     'Accept' => 'application/json', 
    ), 
    Array(
     'grant_type' => 'client_credentials', 
     'client_id'  => $application_id, 
     'client_secret' => $application_secret, 
     'resource'  => 'https://management.core.windows.net/', 
    ) 
); 

$response = $request->send(); 
$body = $response->getBody(true); 

新的代碼我工作:

$client = new GuzzleHttp\Client(); 
$response = $client->request(
    'POST', 
    "https://login.microsoftonline.com/{$tenant_id}/oauth2/token", 
    Array(
     GuzzleHttp\RequestOptions::JSON => Array(
      'grant_type' => 'client_credentials', 
      'client_id'  => $application_id, 
      'client_secret' => $application_secret, 
      'resource'  => 'https://management.core.windows.net/', 
     ) 
    ) 
); 

我已經試過,沒有運氣這麼多的變化。我會很感激任何人都可以提供的見解。

謝謝!

回答

1

嗯,我想在這裏發佈幫助引導我對此的想法。我能夠得到它的工作。對於同一艘船上的其他人,這裏是我想出的解決方案:

$client = new GuzzleHttp\Client(); 
$response = $client->request(
    'POST', 
    "https://login.microsoftonline.com/{$tenant_id}/oauth2/token", 
    Array(
     'form_params' => Array(
      'grant_type' => 'client_credentials', 
      'client_id'  => $application_id, 
      'client_secret' => $application_secret, 
      'resource'  => 'https://management.core.windows.net/', 
     ) 
    ) 
); 
相關問題