问题
I'm using Laravel 5.7
and Laravel/Socialite 3.1
.
I want to login using a Facebook
app I just configured for this project.
These are the main files I have configured for this:
/.env
...
FACEBOOK_CLIENT_ID=***
FACEBOOK_CLIENT_SECRET=***
FACEBOOK_CALLBACK_URL=http://localhost:8000/auth/facebook/callback
/config/services.php
<?php
return [
...
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect' => env('FACEBOOK_CALLBACK_URL'),
],
];
/routes/api.php
<?php
use Illuminate\Http\Request;
...
Route::get('auth/facebook', 'SocialiteController@redirectToProviderFacebook');
Route::get('auth/facebook/callback', 'SocialiteController@handleProviderCallbackFacebook');
/app/Http/Controllers/SocialiteController.php
<?php
namespace App\Http\Controllers;
use Socialite;
class SocialiteController extends Controller
{
public function redirectToProviderFacebook()
{
return Socialite::driver('facebook')->redirect();
}
public function handleProviderCallbackFacebook()
{
$user = Socialite::driver('facebook')->user();
print_r($user->token);
}
}
My problem is that for some reason I get the error:
RuntimeException
Session store not set on request.
as you can see on the following image:
I don't want to use sessions on this project at all. I just want to get the token
from Facebook
on the callback inside: function handleProviderCallbackFacebook()
.
Any idea on how to solve this issue?
Thanks!
回答1:
From the Socialite documentation
The stateless method may be used to disable session state verification. This is useful when adding social authentication to an API:
return Socialite::driver('google')->stateless()->user();
来源:https://stackoverflow.com/questions/52917631/runtimeexception-session-store-not-set-on-request-laravel-socialite-facebo