Laravel、Guzzle 和 Salesforce - 不支持的授权类型
Laravel, Guzzle, and Salesforce - Unsupported Grant Type
我正在尝试使用 Laravel 和 Guzzle 从 Salesforce 获取令牌。通过邮递员尝试时,登录工作正常。当我尝试端点调用时,出现 unsupported_grant_type 错误。
这是我的代码:
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);
}
此错误消息主要表示他们没有在您的请求中找到 'grant_type' 参数。
您似乎正在使用 Psr7\Request、第三个参数 - headers 创建请求。因此,您将以 header.
的形式发送参数
检查这个例子:
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'
]
]
);
}
我正在尝试使用 Laravel 和 Guzzle 从 Salesforce 获取令牌。通过邮递员尝试时,登录工作正常。当我尝试端点调用时,出现 unsupported_grant_type 错误。
这是我的代码:
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);
}
此错误消息主要表示他们没有在您的请求中找到 'grant_type' 参数。
您似乎正在使用 Psr7\Request、第三个参数 - headers 创建请求。因此,您将以 header.
的形式发送参数检查这个例子:
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'
]
]
);
}