Léo*_*oco 2 php redirect laravel-socialite laravel-5.4
我正在使用Laravel 5.4,Socialite因此我的用户可以使用Facebook.
我的网站使用子域newyork.example.com,paris.example.com example.com
Facebook URL回调登录的重定向必须absolute如此我设置http://example.com
public function redirectToProvider()
{
$_SESSION['originalURL'] ="http://paris.example.com";
return Socialite::driver('facebook')
->scopes(['rsvp_event', 'public_profile'])
->redirect();
}
Run Code Online (Sandbox Code Playgroud)
public function handleProviderCallback(SocialAccountService $service)
{
$user = $service->createOrGetUser(Socialite::driver('facebook')->user());
// $user->token;
Auth::login($user, true);
$originalURL = $_SESSION['originalURL'];
return redirect()->to($originalURL);
}
Run Code Online (Sandbox Code Playgroud)
当我在route登录/ FACEBOOK我可以看到原始URLparis.example.com与HTTP_POST
当我在路由login/facebook/callback的HTTP_POST是example.com,因为重定向的URL是example.com。我尝试将 URL 保存在 asession var但$_SESSION为空。
在 facebook 登录回调重定向后如何获取原始 url。? 所以如果我开始登录过程,paris.example.com我被重定向到example.com然后我得到保存 url 被重定向
'cookie' => 'laravel_session',
/*
|--------------------------------------------------------------------------
| Session Cookie Path
|--------------------------------------------------------------------------
|
| The session cookie path determines the path for which the cookie will
| be regarded as available. Typically, this will be the root path of
| your application but you are free to change this when necessary.
|
*/
'path' => '/',
/*
|--------------------------------------------------------------------------
| Session Cookie Domain
|--------------------------------------------------------------------------
|
| Here you may change the domain of the cookie used to identify a session
| in your application. This will determine which domains the cookie is
| available to in your application. A sensible default has been set.
|
*/
'domain' => env('SESSION_DOMAIN', '.localhost.com'),
/*
|--------------------------------------------------------------------------
| HTTPS Only Cookies
|--------------------------------------------------------------------------
|
| By setting this option to true, session cookies will only be sent back
| to the server if the browser has a HTTPS connection. This will keep
| the cookie from being sent to you if it can not be done securely.
|
*/
'secure' => env('SESSION_SECURE_COOKIE', false),
/*
|--------------------------------------------------------------------------
| HTTP Access Only
|--------------------------------------------------------------------------
|
| Setting this value to true will prevent JavaScript from accessing the
| value of the cookie and the cookie will only be accessible through
| the HTTP protocol. You are free to modify this option if needed.
|
*/
'http_only' => true,
Run Code Online (Sandbox Code Playgroud)
小智 5
我用这种方式,它的工作
public function socialConnectRedirect($type, Request $request)
{
Session::put('redirect', $request->input('redirectTo'));
if($type=='facebook'){
return Socialite::driver($type)->scopes(['email', 'public_profile', 'user_birthday', 'user_location'])->redirect();
}
return Socialite::driver($type)->redirect();
}
Run Code Online (Sandbox Code Playgroud)
在handleSocialCallback函数中,用户登录后
Auth::login($checkUser);
return redirect(Session::get('redirect'));
Session::forget('redirect');
Run Code Online (Sandbox Code Playgroud)