Php Laravel 5.4 JWT身份验证不适用于curl
我使用的是tymondesigns/jwtauth包,在尝试使用curl对用户进行身份验证时遇到了一个非常奇怪的问题JWTAuth::TRUMENT($credentials)始终返回false,即使凭据正确。我在firefox上使用HttpRequester插件测试了它,它可以使用它,它返回令牌,为什么它不能使用curl 这是身份验证码Php Laravel 5.4 JWT身份验证不适用于curl,php,authentication,curl,Php,Authentication,Curl,我使用的是tymondesigns/jwtauth包,在尝试使用curl对用户进行身份验证时遇到了一个非常奇怪的问题JWTAuth::TRUMENT($credentials)始终返回false,即使凭据正确。我在firefox上使用HttpRequester插件测试了它,它可以使用它,它返回令牌,为什么它不能使用curl 这是身份验证码 try { //i checked that the credentials are correctly received at this p
try {
//i checked that the credentials are correctly received at this point, even when using curl
if (! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) { }
你以前见过类似的东西吗
这是我在客户端使用的旋度
//set headers
$headers=[];
if($method == 'post'){
$headers[]= 'Content-Type: application/x-www-form-urlencoded';
}
else{
$headers[]='Content-Type: text/plain; charset=UTF-8';
}
if(isset($apiToken) && $apiToken != ''){
$headers[]= 'Authorization: Bearer '.$apiToken;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if($method == 'post'){
curl_setopt($ch, CURLOPT_POST, true);
if(isset($parameters)){
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parameters));
}
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
$result['content'] = curl_exec($ch);
$parameters数组只包含电子邮件和密码,据我所知,JWTAuth::trunt()只需要这些参数就可以工作(事实上,它在Firefox HttpRequester中也可以工作),也许它与laravel的警卫系统或其他东西有关
更新:
我已经用GET方法而不是POST进行了测试,但是我得到了相同的结果,它也不授权
我刚刚使用命令行curl对其进行了测试,它正在工作,这就是我所做的:
curl-X GET'http://myapi.cc/api/auth?email=XXXXXX&password=XXXXX“
另一方面,正是由于PHP Curl导致了这个问题如果您认为Curl请求就是问题所在,那么应该显示该代码。
$credentials
包含什么?如果我使用Log::info($credentials),它将显示以下数组:local.info:array('email'=>'[用户邮件],'password'=>'[用户密码],)