Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nolros's avatar
Level 23

Please help or post working Socialite Twitter code

My code below keeps blowing up. It is redirecting fine, but either no temp credentials or reneging them

Route:

Route::get('login/{provider?}', 'MatrixMe\Auth\AuthController@login');

Controller

    /**
     * @param   SocialAuthManager $socialAuthManager
     * @param   Illuminate\Http;Request $request
     * @param   null $provider
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function login(SocialAuthManager $socialAuthManager, Request $request, $provider = null)
    {
        return $socialAuthManager->execute($request->all(), $this, $provider);
    }

use Illuminate\Auth\Guard; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Session; use Laravel\Socialite\Contracts\Factory as Socialite;

class SocialAuthManager {

    private $socialite;
    private $auth;
    private $users;

    public function __construct(Socialite $socialite, Guard $auth, UserRepository $users)
    {
        $this->socialite = $socialite;
        $this->users = $users;
        $this->auth = $auth;
    }

    public function execute($request, $listener, $provider)
    {
        if (!$request)
        {
            return $this->getAuthorizationFirst($provider);
        }

        $user = $this->getSocialUser($provider);

        dd($user);
    }

    private function getAuthorizationFirst($provider)
    {
        return $this->socialite->driver($provider)->redirect();
    }

    private function getSocialUser($provider)
    {
        return $this->socialite->driver($provider)->user();
    }

}

Errors:

InvalidArgumentException in Server.php line 148:
Temporary identifier passed back by server does not match that of stored temporary credentials.
Potential man-in-the-middle.
in Server.php line 148
at Server->getTokenCredentials(object(TemporaryCredentials), '9UBAZMB0Mi4p4AnI67mLc36xwiI4SQTg', '0cev5olXqssstlLUvy3cSUCYiic9Jj9B') in AbstractProvider.php line 85
at AbstractProvider->getToken() in TwitterProvider.php line 14
at TwitterProvider->user() in SocialAuthManager.php line 42
at SocialAuthManager->getSocialUser('twitter') in SocialAuthManager.php line 30
at SocialAuthManager->execute(array('oauth_token' => '9UBAZMB0Mi4p4AnI67mLc36xwiI4SQTg', 'oauth_verifier' => '0cev5olXqssstlLUvy3cSUCYiic9Jj9B'), object(AuthController), 'twitter') in AuthController.php line 125
at AuthController->login(object(SocialAuthManager), object(Request), 'twitter')
at call_user_func_array(array(object(AuthController), 'login'), array(object(SocialAuthManager), object(Request), 'provider' => 'twitter')) in Controller.php line 246
at Controller->callAction('login', array(object(SocialAuthManager), object(Request), 'provider' => 'twitter')) in ControllerDispatcher.php line 162
at ControllerDispatcher->call(object(AuthController), object(Route), 'login') in ControllerDispatcher.php line 107
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))

OR

Argument 1 passed to League\OAuth1\Client\Server\Server::getTokenCredentials() must be an instance of League\OAuth1\Client\Credentials\TemporaryCredentials, null given
0 likes
3 replies
cbil360's avatar

I came across the question while searching for my issue.Even I am integrating Socialite.Maybe you could help me,I am facing issue with the cacert.pem file while connecting to facebook.

cURL error 77: error setting certificate verify locations:
CAfile: cacert.pem

This is the error.

Please or to participate in this conversation.