【问题标题】:Trouble forming post to get Azure token using Guzzle6 (Error: AADSTS90014)使用 Guzzle6 生成获取 Azure 令牌的帖子时遇到问题(错误:AADSTS90014)
【发布时间】: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


    【解决方案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/',
            )
        )
    );
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-22
    • 2017-04-22
    • 2014-05-08
    • 2016-01-22
    • 1970-01-01
    相关资源
    最近更新 更多