请求缺少必需参数,包括无效参数护照身份验证
The request is missing a required parameter, includes an invalid parameter passport authentication
我正在为我的项目使用带 lumen 的护照身份验证,并使用默认路由进行设置。但是我尝试从 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()]);
}
}
在对逻辑解决方案进行不必要的搜索后,我发现在 form_params
块 client_id
中括号前有一个 space 字符。
我正在为我的项目使用带 lumen 的护照身份验证,并使用默认路由进行设置。但是我尝试从 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()]);
}
}
在对逻辑解决方案进行不必要的搜索后,我发现在 form_params
块 client_id
中括号前有一个 space 字符。