Reputation: 12847
Using official Laravel Docs 5.1 - Socialite, I set my routed and edited my AuthController.
public function redirectToProvider()
{
return Socialite::driver('facebook')
->scopes(['public_profile', 'email'])->redirect();
}
It works perfectly and returns
http://domain.dev/auth/facebook/callback?code=AQDLFlYr...
Then I used Laracasts' Socialite - Laravel 5.0, I tried turn my one into a proper Facebook authentication. I did everything until (min. 12.11, specifically) in the video. (At 12.11 he recaps the stuff in 15 sec). This is what I am trying to do.
Now, when I change my AuthController
to:
public function redirectToProvider(AuthenticateUser $authenticateUser, Request $request)
{
return $authenticateUser->execute($request->has('code'));
}
...and have my AuthenticateUser class
like this:
use Illuminate\Contracts\Auth\Guard; (PS. I changed Authenticator to Guard)
class AuthenticateUser {
private $users;
private $socialite;
private $auth;
public function __construct(UserRepository $users, Socialite $socialite, Guard $auth)
{
$this->users = $users;
$this->socialite = $socialite;
$this->auth = $auth;
}
public function execute($hasCode)
{
// dd($hasCode) *First dd
if ( ! $hasCode) return $this->getAuthorizationFirst();
$user = $this->socialite->driver('facebook')->user();
// dd($hasCode) *Second dd
// dd($user) *Third dd
}
private function getAuthorizationFirst()
{
return $this->socialite->driver('facebook')
->scopes(['public_profile', 'email'])->redirect();
}
}
*UserRepository is currently empty.
When I use *First dd
, I receive False
on the screen.
When I use *Second dd
, I receive True
.
When I use *Third dd
, I receive nothing.
In all of these instances, now, I am receiving http://domain.dev/auth/facebook?code=9329409329042
.
Edit:
I added return
and now the link includes ?code=9390249032...
, however when I use *Third dd
- dd($user)
, still nothing gets returned
I managed to come until here:
public function execute($hasCode)
{
dd($hasCode); // returns FALSE now
if ( ! $hasCode) return $this->getAuthorizationFirst();
dd($hasCode); // returns TRUE now
$user = $this->socialite->driver('facebook')->user();
dd($user); // BUT STILL RETURNS NOTHING
}
.. and link includes ?code=9943290...
$user = $this->socialite->driver('facebook')->user();
is the part not working/converting as dd($user) is not returning anything..Upvotes: 0
Views: 676
Reputation: 7447
It looks like you might have forgot the return.
return $authenticateUser->execute($request->has('code'));
Upvotes: 1