Laravel Socialite-重定向前保存URL [英] Laravel Socialite - Save URL before redirection
问题描述
我使用的是 Laravel 5.4
和 Socialite
,因此我的用户可以使用 Facebook
登录.
I'm using Laravel 5.4
and Socialite
so my users can log in with Facebook
.
我的网站使用子域 newyork.example.com
、paris.example.com
example.com
My website works with subdomain newyork.example.com
, paris.example.com
example.com
回调登录的 Facebook URL
重定向必须是绝对
,因此我将 http://example.com
The Facebook URL
redirect for the callback login has to be absolute
so I set http://example.com
public function redirectToProvider()
{
$_SESSION['originalURL'] ="http://paris.example.com";
return Socialite::driver('facebook')
->scopes(['rsvp_event', 'public_profile'])
->redirect();
}
登录/facebook/回调
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);
}
问题
当我进入 route
登录名/facebook时,我可以使用 HTTP_POST
Problems
When I am in the route
login/facebook I can view the original URL paris.example.com
with HTTP_POST
当我在 login/facebook/callback
路线中时,由于重定向的URL是 HTTP_POST
是 example.com
> example.com .我尝试将 URL 保存在 session var
中,但 $_SESSION
为空.
When I am in the route login/facebook/callback
the HTTP_POST
is example.com
since the URL of the redirection is example.com
. I tries to save the URL in a session var
but $_SESSION
is empty.
如何在Facebook登录回调重定向后获取原始URL.?因此,如果我使用 paris.example.com
开始登录过程,则将我重定向到 example.com
,然后获取要重定向的保存URL
How I can do to get the original url after the facebook login callback redirection. ? So if I started the login process with paris.example.com
I'm redirected to example.com
and then I get the save url to be redirected
'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,
推荐答案
关键不是使用 $ _ SESSION
,而是使用 session(['city'=>'paris'])
;和 session('city')
来检索值.
The key was not to use $_SESSION
but session(['city' => 'paris'])
; and session('city')
to retrieve the value.
这篇关于Laravel Socialite-重定向前保存URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!