【发布时间】:2021-06-11 23:07:26
【问题描述】:
我在我的项目中使用带流明的护照身份验证,并使用默认路由进行设置。但是我尝试从 AuthLoginController 测试我的登录路由,我回来了:
"Client error: POST http://api.restservice/v1/oauth/token resulted in a 400 错误请求 response:\n{\"error\":\"invalid_request\",\"error_description\":\"The request is missing a required parameter, includes an invalid paramet (truncated...)\n".
邮递员json
{
"client_secret" : "IFCeKiKNA7zdmOC1yzgWQJvxtHKHOu1WwdDq1hMH",
"grant_type" : "password",
"client_id" : "2",
"email" : "fhegmann@example.com",
"username" : "fhegmann@example.com",
"password" : "123456"
}
AuthLoginController.php
{
public function login(Request $request)
{
$email = $request->email;
$password = $request->password;
//the fields if empty or not
if (empty($email) or empty($password)) {
return response()->json(['status' => 'error', 'message' => 'You must fill all fields']);
}
$client = new Client();
try {
return $client->post('http://api.restservice/v1/oauth/token', [
'form_params' => [
'client_secret' => 'IFCeKiKNA7zdmOC1yzgWQJvxtHKHOu1WwdDq1hMH',
'grant_type' => 'password',
'client_id ' => 2,
'username' => $request->email,
'password' => $request->password
]
]);
} catch (BadResponseException $e) {
return response()->json(['status' => 'error', 'message' => $e->getMessage()]);
}
}
【问题讨论】:
-
尝试以
JSON发送。将form_params更改为json -
我尝试了所有类型的主体
app/json, form-data, x-www-form-urlencoded,并从邮递员的对象主体中删除了username.....没什么,同样的错误。