简体   繁体   中英

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?

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.

TwitterProvider needs secret with token you could use this method

userFromTokenAndSecret

Example

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM