Laravel 4 Auth with Facebook (no password authentication)

后端 未结 2 1270
死守一世寂寞
死守一世寂寞 2021-01-22 18:47

I\'m trying to set up an authentication system with Laravel 4 with a Facebook login. I am using the madewithlove/laravel-oauth2 package for Laravel 4.

Of course, ther

相关标签:
2条回答
  • 2021-01-22 19:43

    You have to implement UserInterface to your model for Auth to work properly

    use Illuminate\Auth\UserInterface;
    class Fan extends Eloquent implements UserInterface{
    ...
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }
    
    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }
    }
    

    getAuthIdentifier and getAuthPassword are abstract method and must be implemented in you class implementing UserInterface

    0 讨论(0)
  • 2021-01-22 19:49

    To login any user into the system, you need to use the User model, and I bet inherited classes will do the trick as well but I'm not sure.

    Anyway, your Fan model does not associate with the User model/table in any way and that's a problem. If your model had a belong_to or has_one relationship and a user_id field then you could replace Auth::login($user) with Auth::loginUsingId(<some id>).


    Original answer:

    You are missing an extra method call: ->get() or ->first() to actually retrieve the results:

    $fan = Fan::where('fbid', '=', $user['uid'])->first();
    

    Alternatively, you can throw an exception to see what's going on:

    $fan = Fan::where('fbid', '=', $user['uid'])->firstOrFail();
    

    If you see different errors, update your question with those errors.

    0 讨论(0)
提交回复
热议问题