使用guzzle6(错误:AADSTS90014)形成帖子以获取Azure代币



我们正在从guzzle3移动到guzzle6。我写了一个过程,以身份验证和访问在Guzzle3中工作正常的Azure Management API。但是,我无法弄清楚如何使其在Guzzle6中工作。目的是获取访问令牌,然后将其用于Azure Management API的后续请求。

原始代码:

$client = new GuzzleHttpClient();
$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 GuzzleHttpClient();
$response = $client->request(
    'POST',
    "https://login.microsoftonline.com/{$tenant_id}/oauth2/token",
    Array(
        GuzzleHttpRequestOptions::JSON => Array(
            'grant_type'    => 'client_credentials',
            'client_id'     => $application_id,
            'client_secret' => $application_secret,
            'resource'      => 'https://management.core.windows.net/',
        )
    )
);

我尝试了很多变化,没有运气。我会感谢任何人都能提供的任何见解。

谢谢!

好吧,我想在这里发布的文章有助于指导我对此的想法。我能够让它上班。对于同一条船上的其他任何人,这是我提出的解决方案:

$client = new GuzzleHttpClient();
$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/',
        )
    )
);

最新更新