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 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?