ollieread / multiauth

Laravel multi auth
441 stars 109 forks source link

Setup Challenge. #16

Closed ajarti closed 10 years ago

ajarti commented 10 years ago

Hi there,

Firstly thanks for an amazing tool!

My apologies for the newbie question, in your setup you say:

Next you open up app/config/app.php and replace the AuthServiceProvider with
"Ollieread\Multiauth\MultiauthServiceProvider"

Do you mean add it to the 'providers' section and comment out or delete the 'Illuminate\Auth\AuthServiceProvider' reference, or do you mean update the 'Auth' alias in the 'aliases' with MultiAuth. I have added it and commented out the original Auth Provider, but I am getting:

{"error":{"type":"ErrorException","message":"Argument 1 passed to Illuminate\\Auth\\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\\Auth\\UserInterface, instance of Admin given, called in \/Users\/xxx\/Documents\/Webdev\/engine\/vendor\/laravel\/framework\/src\/Illuminate\/Auth\/Guard.php on line 316 and defined","file":"\/Users\/xxx\/Documents\/Webdev\/engine\/vendor\/laravel\/framework\/src\/Illuminate\/Auth\/EloquentUserProvider.php","line":73}}

when running:

Auth::admin()->attempt(array(
            'email'     => $input['email'],
            'password'  => $input['password'],
        ))

with a auth config of:

return array(

'multi' => array(
    'admin' => array(
        'driver' => 'eloquent',
        'model' => 'Admin'
    )
),

'reminder' => array(

    'email' => 'emails.auth.reminder',

    'table' => 'password_reminders',

    'expire' => 60,

),

);

It seems to still be trying to use the original Auth?

Usually one just adds new Service Providers to the 'providers' section.

Thanks in advance.

ajarti commented 10 years ago

Ok I figured it out ...

You have to comment out the original

//'Illuminate\Auth\AuthServiceProvider',
//'Illuminate\Auth\Reminders\ReminderServiceProvider',

Add the new providers to the 'providers' section.

What got me was that my new custom model Admins did not implement UserInterface & RemindableInterface, nor did it include the three requisite methods from the interfaces like so:

<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class Admin extends \Eloquent implements UserInterface, RemindableInterface {
    protected $table = 'admins';
    protected $fillable = [];
    protected $softDelete = true;

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the e-mail address where password reminders are sent.
     *
     * @return string
     */
    public function getReminderEmail()
    {
        return $this->email;
    }

}

Might be helpful for some to mention this .. lol .. or they can just read this issue.

Thanks again for a killer tool, just what I needed :)

ollieread commented 10 years ago

I do state in the documentation that you must replace the original serviceprovider, in the serviceprovider list, but there seems to be a fair bit of confusion regarding that point.

ajarti commented 10 years ago

Hahahah I know ... some of us are a bit more challenged than others .. lol Without having read the Laravel Auth documentation, I would never have known to extend my Multi users with the relevant interfaces. But that's why they say RTFM!

And to make it easier, If you haven't subscribed to Laracasts do it now, they are an invaluable resource, thanks Jeff! https://laracasts.com/tags/security