dshp9580656 2017-01-16 19:12
浏览 98
已采纳

Laravel,Guzzle和Salesforce - 不支持的授权类型

I'm trying to get a token from Salesforce using Laravel and Guzzle. When trying through Postman, the login works fine. When I try my endpoint call, I get an unsupported_grant_type error.

Here is my code:

public function login(LoginRequest $request) {
    $client = new Client();

    $salesforce = new Request(
      'POST',
      'https://test.salesforce.com/services/oauth2/token',
      [
        'headers' => [
          'Content-Type' => 'application/x-www-form-urlencoded'
        ],
        'form_params' => [
          'username' => $request->email,
          'password' => $request->password,
          'client_id' => '<super_secret_id>',
          'client_secret' => '<super_secret_secret>',
          'grant_type' => 'password'
        ]
      ]);

    $response = $client->send($salesforce);
  }
  • 写回答

1条回答 默认 最新

  • dt3358 2017-01-16 19:46
    关注

    This error message mostly means that they didn't find 'grant_type' parameter in your request.

    It seems you're creating a request with Psr7\Request, 3rd parameter - headers. So, you're sending your parameters as a header.

    Check this example:

    public function login(LoginRequest $request) {
        $client = new Client();
    
        $response = $client->request(
            'POST',
            'https://test.salesforce.com/services/oauth2/token',
            [
                'headers' => [
                    'Content-Type' => 'application/x-www-form-urlencoded'
                ],
                'form_params' => [
                    'username' => $request->email,
                    'password' => $request->password,
                    'client_id' => '<super_secret_id>',
                    'client_secret' => '<super_secret_secret>',
                    'grant_type' => 'password'
                ]
            ]
        );
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题