【问题标题】:Laravel HTTP Client Retrieve REST API Access TokenLaravel HTTP 客户端检索 REST API 访问令牌
【发布时间】:2023-03-15 22:42:01
【问题描述】:

尝试从 MS Azure 检索访问令牌

类似这样的:

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Http;
use Illuminate\Http\Client\Response;

class HttpController extends Controller
{
    public function index()
    {
        $url = "https://login.microsoftonline.com/[tenantId]/oauth2/token";

        $response = HTTP::post($url,
        [
            'grant_type' => 'client_credentials',
            'client_Id' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
            'client_secret' => '***************************',
            'resource' => 'https://management.azure.com',
        ]);

         dd($response);
    }
}

得到以下错误:

"error": "invalid_request", "error_description": "AADSTS900144: 请求正文必须包含以下参数:'grant_type'

【问题讨论】:

    标签: authentication access-token guzzle laravel-7


    【解决方案1】:
    $response = HTTP::asForm()->post($url,
            [
                'grant_type' => 'client_credentials',
                'client_Id' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
                'client_secret' => '***************************',
                'resource' => 'https://management.azure.com',
                ]
            );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-03
      • 2022-07-14
      • 1970-01-01
      • 2020-04-23
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      • 2012-08-30
      相关资源
      最近更新 更多