[英]Laravel Socialite - handleProviderCallback() method not showing stored session
I am trying to integrate Socialite in my Laravel project.我正在尝试将 Socialite 集成到我的 Laravel 项目中。 I am trying to store a session in buyerSignup.blade.php file and then trying to get that session value in Socialite's handleProviderCallback() method.
我试图在buyerSignup.blade.php 文件中存储一个会话,然后尝试在Socialite 的handleProviderCallback() 方法中获取该会话值。 But it is not showing any value don't know why.
但它没有显示任何价值不知道为什么。 Although the other method redirectToProvider() showing the session value.
尽管另一个方法 redirectToProvider() 显示了会话值。
I need that session value in handleProviderCallback() method to process it and take actions based upon the value of session.我需要 handleProviderCallback() 方法中的会话值来处理它并根据会话的值采取行动。 Below is a actual of code that I am using.
下面是我正在使用的实际代码。
Storing a session value in buyerSignup.blade.php在buyerSignup.blade.php 中存储会话值
@php
\Session::put('buyerSignupFb','true');
@endphp
Trying to get the above stored value in LoginController's handleProviderCallback() method.试图在 LoginController 的 handleProviderCallback() 方法中获取上述存储的值。
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Auth;
use App\sellerData;
use App\buyerData;
use App\sellerDealCat;
use App\subCatData;
use App\Session;
use App\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\DB;
use Socialite;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/home';
public function __construct()
{
$this->middleware('guest')->except('logout');
$this->middleware('guest:seller')->except('logout');
$this->middleware('guest:buyer')->except('logout');
}
public function redirectToProvider()
{
return Socialite::driver('facebook')->redirect();
}
public function handleProviderCallback()
{
//cant get the value of the session defined in buyerSignup.blade.php
// echo doesn't work too
return \Session()->get('buyerSignupFb');
}
}
Any suggestion what I am doing wrong or how to make it work.任何建议我做错了什么或如何使它工作。 TIA
TIA
U doing all good, but not enought, first u set a redirect provider你做得很好,但还不够,首先你设置一个重定向提供者
public function redirectToProvider()
{
return Socialite::driver('facebook')->stateless()->redirect();
}
it's good, when user will give access to his token, u need to handle callback in handleProviderCallback()
, where u need to exchange user auth code
to acces token
.很好,当用户允许访问他的令牌时,您需要在
handleProviderCallback()
处理回调, handleProviderCallback()
需要将用户auth code
交换auth code
访问acces token
。 All of this socialite makes automatically, all what u need its just call it所有这些社交名媛都是自动制作的,你需要的所有东西都可以称之为
public function handleProviderCallback()
{
$externalUser = Socialite::driver('facebook')->stateless()->user();
\\check if user exists, if not create
$auth->login($user, true);
if ($user->type = 'seller'){$this->redirectTo = '/forSellers'} else {$this->redirectTo = '/forOtherGroup'}
return redirect($this->redirectPath());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.