【发布时间】:2017-11-05 21:37:17
【问题描述】:
我正在使用Laravel 5.4 和Socialite,因此我的用户可以使用Facebook 登录。
我的网站使用子域 newyork.example.com, paris.example.com example.com
回调登录的Facebook URL重定向必须是absolute所以我设置http://example.com
登录/facebook
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 时,我可以查看原始 URL paris.example.com 和 HTTP_POST
当我在路由 login/facebook/callback 中时,HTTP_POST 是 example.com,因为重定向的 URL 是 example.com。我尝试将 URL 保存在 session var 中,但 $_SESSION 为空。
问题
如何在 facebook 登录回调重定向后获取原始 url。 ?因此,如果我使用 paris.example.com 开始登录过程,我将被重定向到 example.com,然后我会重定向保存 url
sessions.php
'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,
【问题讨论】:
-
您是否将所有 cookie 存储在 example.com 级别的域中?如果是这样,会话可以在所有子域之间共享,您可以从其中任何一个访问您放入会话中的数据
-
您也可以将数据放在发送给 Facebook 的
state中。我很想为此写一个答案,但我目前正面临社交名流的另一个问题(在寻找另一个问题时发现了这个问题) -
@Kaktus,我复制了
sessions文件。因此,它可能会回答您有关 cookie 存储的问题。state在哪里?既然回调url是预先固定的,它不会被删除吗?
标签: php redirect laravel-5.4 laravel-socialite