我正在使用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时,我可以使用paris.example.com
查看原始URL HTTP_POST
当我在路由login/facebook/callback
中时,由于重定向的URL是HTTP_POST
,所以example.com
是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,
参考方案
我用这种方式,这是工作
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();
}
用户登录后,在handleSocialCallback函数中
Auth::login($checkUser);
return redirect(Session::get('redirect'));
Session::forget('redirect');
PHP Laravel从另一个驱动器读取文件 - php我目前正在学习Laravel。我想知道是否有一种方法可以在Laravel中使用Storage::从另一个硬盘访问文件(使用Windows)。例如,我在驱动器C:上安装了带有Laravel的Xampp,但是我想访问网站目录之外的E:上的文件。我试过使用Storage::files('E:')和File::files('E:…
Laravel 5排序具有关系的雄辩模型 - php我有一个要基于关系属性进行排序的模型。主模型Resultado具有类型respondente的关系belongsTo,而respondente具有关系usuario。我想获取具有这些关系的Resultado并按usuario name属性(列)对结果进行排序。我试过了$resultados = Diagnostico\Resultado::with(…
检查对象是否已在集合中-Laravel - php当我循环一系列不同的结果时,我希望将对象添加到新集合中。查询:$osRed = Item::where('category', 'Hardware') ->where(function ($query) { $query->where('operating_system', '…
Laravel-使用雄辩的语言在开始日期和结束日期之间选择行 - php我想将此查询转换为雄辩的laravel,select * from schedule where (now() between start_date and end_date); 我尝试使用whereBetween,但是出现了一些错误。$schedule = Schedule::whereBetween(Carbon::now(), ['start…
laravel Hash::make继续给出不同的结果 - php我想在laravel 4中使用身份验证我改了桌子和莫贝尔的名字当用户注册时,我拥有密码并将其保存,哈希为:$password = Hash::make(Input::get('password')); 然后当用户登录时,我想先对他/她进行身份验证。我这样做是这样的:if (Auth::attempt(array('usernam…