Vico
Vico

Reputation: 1256

Laravel custom authentication

I'm starting to discover Laravel 5, so I might need a bit of your help to understand a few things.

First, I want to develop a login page. It seems that Laravel has a whole authentication system, and I guess I should use it.

Nevertheless, I want to display a login page (I know how to do this!), but after this, I would like to send the credentials to a server via an API call. The server will then tell me if the user is allowed to log in or not.

As far I understand Laravel and authentication, it seems that the authentication system works only with a local DB.

Can you confirm I need to use a custom authentication driver to do this? I've been following this solution but I get this error when loading my page:

FatalErrorException in CustomUserProvider.php line 6:
Interface 'Illuminate\Auth\UserProviderInterface' not found

Any help would be appreciated, feel free to ask me for more information if you need it.

Thanks

Upvotes: 7

Views: 6923

Answers (2)

silverdr
silverdr

Reputation: 2172

I tried following the same thread you mentioned and arrived at the very same results. Then I checked the implementation of native UserProviders (Illuminate/Auth/EloquentUserProvider and Illuminate/Auth/DatabaseUserProvider) and ended up using the same set as in EloquentUserProvider:

<?php namespace App\Auth;

use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;

class MyUserProvider implements UserProvider {
   // Implementation goes here
}

I believe this to be more correct approach as the suggestions from the forum thread seem to be possibly for an older/beta version of L5.

Upvotes: 7

Vico
Vico

Reputation: 1256

Here is my CustomUserProvider file:

<?php namespace App\Auth;

use Illuminate\Contracts\Auth\UserProvider as UserProviderInterface;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\GenericUser;

class CustomUserProvider implements UserProviderInterface {

It's now working :-)

Upvotes: 1

Related Questions