ChrisBratherton
ChrisBratherton

Reputation: 1590

Call to undefined method Laravel\Socialite\One\TwitterProvider::stateless()

I am recieving the following error:

Call to undefined method Laravel\Socialite\One\TwitterProvider::stateless()

The line throwing this error is:

$userData = Socialite::driver($provider)->stateless()->user();

The above works fine for Facebook Login.

Any ideas?

Upvotes: 3

Views: 9445

Answers (4)

Koushik Das
Koushik Das

Reputation: 10813

You can't get user info from Twitter using stateless as Twitter doesn't support OAuth 2.0 as of I'm writing this. Link to twitter dev forum However, I have a found a workaround for login using the API.

However, one way to do this would be to redirect using this

return Socialite::driver('twitter')->redirect();

In your callback, get the returned info using this

Socialite::driver($provider)->user();

Get the token and other info as you wish from here, then, do your thing and store the credentials in the database and get new database row id and encrypt that value and redirect to your login page with that encrypted value. From your login page, do some operations and check if id like that is present, if yes, then try to log in. Now in loginController, do something like this

            $authId = $request->get('authId');
            $authId = decrypt($authId);
            $social = SocialAuth::find($authId);
            $user = User::find($social->user_id);

and then attempt to login that user using id. Redirect to the log in url with more parameters for more security. I hope you get the concept.

Upvotes: 0

Gioacchino Poletto
Gioacchino Poletto

Reputation: 11

In your loginController, in handleProviderCallback function replace:

$userSocial = Socialite::driver($social)->stateless()->user();

with:

$userSocial = Socialite::driver($social)->user();

using:

"laravel/socialite": "^3.0"

in your composer.json require section.

Upvotes: 0

Bdwey
Bdwey

Reputation: 2003

TwitterProvider needs secret with token you could use this method

userFromTokenAndSecret

Example

$user = Socialite::driver('twitter')->userFromTokenAndSecret($token, $secret);

Upvotes: 2

Ohgodwhy
Ohgodwhy

Reputation: 50798

A quick look shows that the TwitterProvider uses a different AbstractProvider than the FacebookProvider.

This AbstractProvider for the TwitterProvider does not implement stateless().

So I suppose what I'm saying is...stateless oAuth is not possible with the TwitterProvider in the Laravel Socialite package out of the box.

Upvotes: 6

Related Questions