2017-06-06 76 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/', 
     ) 
    ) 
); 
相关问题