Hello again!
Anyone know if have any problem with twitter and socialite?
I have in my application login with facebook, google and twitter. Facebook and google works fine with the same logic, but today twitter got loop and never back to application.
I have a simple code
public function getLoginTwitter(AuthenticateTwitter $authenticatetwitter, Request $request)
{
return $authenticatetwitter->execute($request->has('code'));
}
and
<?php
namespace App\Http;
use Illuminate\Contracts\Auth\Guard;
use Laravel\Socialite\Contracts\Factory as Socialite;
use App\Repositories\UserRepository;
class AuthenticateTwitter {
/**
* @var UserRepository
*/
private $user;
/**
* @var Socialite
*/
private $socialite;
/**
* @var Guard
*/
private $auth;
public function __construct(UserRepository $user, Socialite $socialite, Guard $auth)
{
$this->user = $user;
$this->socialite = $socialite;
$this->auth = $auth;
}
/**
* @param $hasCode
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function execute($hasCode)
{
if(!$hasCode) //This $hasCode always false
return $this->getAuthorizationFirst();
$user = $this->user->findByUserNameOrCreate($this->getTwitterUser());
return redirect('/auth/register')->with(['name' => $user->name, 'picture' => $user->picture, 'email' => $user->email]);
}
private function getAuthorizationFirst()
{
return $this->socialite->driver('twitter')->redirect();
}
private function getTwitterUser()
{
return $this->socialite->driver('twitter')->user();
}
}
But when I debug $hasCode always got false.
I have inspected the $_REQUEST and twitter give oauth_token and oauth_verifier never return code.
Can anyone help me?
Thanks in advance