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

thiduzz's avatar

Passport with Social Login

Hello guys,

I developed an API with Laravel Passport that will be used for a mobile app. Everything is working flawlessly but then I started working on Social Network logins (Facebook and G+) in the app and well, I stumbled on the following problem:

When using the grant type = Password it requires a password and Facebook wont provide it and I am afraid of the security issues on using a generated "info hashed" password. I already tweaked the Passport to search for the user by its social network ID with this code on the User model:

public function findForPassport($username)
{
    $user = $this->where('email', $username)->first();
    if(!$user)
    {
        $user = $this->where('social_network_id', $username)->first();
    }
    return $user;
}

But the next step on the \passport\src\Bridge\UserRepository.php is where I need help.

It checks for this condition below and guess what? The $user does not have a password to check since its a social network login.

if (! $user || ! $this->hasher->check($password, $user->password))

What would be your suggestions for this issue? I believe it would be possible to implement my own UserRepository but if so, how would I bind it my with own version of this repository class?

0 likes
3 replies
cleyton's avatar

Hello my friend!

I have the same scenario here. Did you solve this? How?

Agelios's avatar

I used official package https://github.com/laravel/socialite I saved email, name in table 'users' and created new table 'providers' which contains 'provider' (it can be google, facebook..), 'provider_id' (its id where you conected). and 'user_id'. When you connect, you check email in 'users' (firstOrCreate in ORM). So on 1 email you can have lots of providers, password i randomed that would not be possible to enter with email and pass. Maybe I did not understand the question, but i had this solution

Please or to participate in this conversation.