jeudi 11 juillet 2019

Laravel: Indirect User Authentication is not working

I wanted to authenticate a user by id. I wanted to do it in an indirect way. For example I will send a get request to a route and then the closure function of this route will send a post request to another route for authentication.

This is working fine

 Route::get('/test', function(){
    Auth::loginUsingId(1);});

But this is not working fine. But I don't know why. I don't wanted to send csrf token to only 'post-login' route, that's why I excluded it in verifycsrf middleware

Route::get('/test', function(){
$url = 'http://localhost/fps/public/post-login';
$fields = [];

$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 

$result = curl_exec($ch);
echo $result;
dd(Auth::check());

});

Route::post('/post-login',function(){
Auth::loginUsingId(1);
echo Auth::check();
});

The above code output 1 and "false". Actually It should give this output 1 and "true"



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire