【发布时间】:2017-11-06 22:34:06
【问题描述】:
我们正在从 Guzzle3 迁移到 Guzzle6。我编写了一个流程来验证和访问在 Guzzle3 中运行良好的 Azure 管理 API。但是,我无法弄清楚如何让它在 Guzzle6 中工作。目的是获取访问令牌,然后在对 Azure 管理 API 的后续请求中使用该令牌。
原代码:
$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/',
)
)
);
我尝试了很多变化,但都没有运气。如果有人能提供任何见解,我将不胜感激。
谢谢!
【问题讨论】:
标签: php azure oauth-2.0 guzzle6 azure-management-api