0
votes

Laravel Socialite Twitter (Oauth1)

I am having trouble with twitter login via laravel socialite.

Socialite::driver('twitter')->user();

the code above throws an error with message:

Argument 1 passed to League\OAuth1\Client\Server\Server::getTokenCredentials() must be an instance of League\OAuth1\Client\Credentials\TemporaryCredentials, null given

I checked Laravel Socialite documentation and it says that to get the user details of a twitter account, I should use

Socialite::driver('twitter')->userFromTokenAndSecret($token, $tokenSecret);

instead of

Socialite::driver('twitter')->user();

But it isn't explained how to get the $token and $tokenSecret parameter. I hard coded the $token and $tokenSecret using the keys in the twitter application but everytime I log in other account it still uses that account which I understand since the code is hard coded. Is there anyway to get the user's $token and $tokenSecret when they log in? Thank you

1
Did you ever resolve this?Thomas

1 Answers

0
votes

You must obtain the $token and $token_secret from the request.

  $provider = "twitter"  
  $token = trim($request->input("provider_token"));
  $token_secret = trim($request->input("provider_token_secret"));

Then you can use them for OAuth1.0

Socialite::driver($provider)->userFromTokenAndSecret($token, $token_secret);

You cant use Socialite::driver($provider)->user($token); here because OAuth1.0 is used.