Last active
August 22, 2022 12:01
-
-
Save gbuckingham89/672114f782e747b8b99e to your computer and use it in GitHub Desktop.
Blog: Laravel Authentication Customer User Provider Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'providers' => [ | |
'users' => [ | |
'driver' => 'our_provider', | |
], | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Authentication; | |
use Auth; | |
use App\Authentication\UserProvider; | |
use Illuminate\Support\ServiceProvider; | |
class AuthServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Perform post-registration booting of services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
Auth::provider('our_provider', function($app, array $config) { | |
return new UserProvider(); | |
}); | |
} | |
/** | |
* Register bindings in the container. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Authentication; | |
use Illuminate\Contracts\Auth\Authenticatable; | |
class User implements Authenticatable | |
{ | |
/** | |
* @return string | |
*/ | |
public function getAuthIdentifierName() | |
{ | |
// Return the name of unique identifier for the user (e.g. "id") | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getAuthIdentifier() | |
{ | |
// Return the unique identifier for the user (e.g. their ID, 123) | |
} | |
/** | |
* @return string | |
*/ | |
public function getAuthPassword() | |
{ | |
// Returns the (hashed) password for the user | |
} | |
/** | |
* @return string | |
*/ | |
public function getRememberToken() | |
{ | |
// Return the token used for the "remember me" functionality | |
} | |
/** | |
* @param string $value | |
* @return void | |
*/ | |
public function setRememberToken($value) | |
{ | |
// Save a new token user for the "remember me" functionality | |
} | |
/** | |
* @return string | |
*/ | |
public function getRememberTokenName() | |
{ | |
// Return the name of the column / attribute used to store the "remember me" token | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Authentication; | |
use Illuminate\Contracts\Auth\UserProvider as IlluminateUserProvider; | |
class UserProvider implements IlluminateUserProvider | |
{ | |
/** | |
* @param mixed $identifier | |
* @return \Illuminate\Contracts\Auth\Authenticatable|null | |
*/ | |
public function retrieveById($identifier) | |
{ | |
// Get and return a user by their unique identifier | |
} | |
/** | |
* @param mixed $identifier | |
* @param string $token | |
* @return \Illuminate\Contracts\Auth\Authenticatable|null | |
*/ | |
public function retrieveByToken($identifier, $token) | |
{ | |
// Get and return a user by their unique identifier and "remember me" token | |
} | |
/** | |
* @param \Illuminate\Contracts\Auth\Authenticatable $user | |
* @param string $token | |
* @return void | |
*/ | |
public function updateRememberToken(Authenticatable $user, $token) | |
{ | |
// Save the given "remember me" token for the given user | |
} | |
/** | |
* Retrieve a user by the given credentials. | |
* | |
* @param array $credentials | |
* @return \Illuminate\Contracts\Auth\Authenticatable|null | |
*/ | |
public function retrieveByCredentials(array $credentials) | |
{ | |
// Get and return a user by looking up the given credentials | |
} | |
/** | |
* Validate a user against the given credentials. | |
* | |
* @param \Illuminate\Contracts\Auth\Authenticatable $user | |
* @param array $credentials | |
* @return bool | |
*/ | |
public function validateCredentials(Authenticatable $user, array $credentials) | |
{ | |
// Check that given credentials belong to the given user | |
} | |
} |
Declaration of App\Authentication\UserProvider::updateRememberToken(App\Authentication\Authenticatable $user, $token) must be compatible with Illuminate\Contracts\Auth\UserProvider::updateRememberToken(Illuminate\Contracts\Auth\Authenticatable $user, $token)
I fixed it by adding this line:
use Illuminate\Contracts\Auth\Authenticatable;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you please update this to 5.6?