I am new to PHP and to Laravel .
I follow this guide to implement a custom user provider :
https://blog.georgebuckingham.com/laravel-52-auth-custom-user-providers-drivers/
I am using Laravel 5.3 version .
I’ll briefly explain what I need: my Laravel application is just a front-panel application, all the business logic that includes user authentication is done using Java back end application strong>, which provides REST web services .
Making a call:
http:
and passing the username and password as basic authentication, I get a JSON response that represents the registered user:
{
"userName": "Painkiller",
"email": "painkiller@gmail.com",
"enabled": true
}
So, in my Laravel application, I have to make this call and then parse the previous returned JSON object to generate an authenticated object in the foreground application session.
4 , , , -, :
, , , Laravel http://localhost:8000/login page, retrieveByCredentials ( $credentials), - REST .
, , , , ...
:
https://laravel.com/docs/5.3/authentication#adding-custom-user-providers
, :
retrieveByCredentials Auth:: . "" , . , "where" $ [ ' ']. Authenticatable. .
validateCredentials $user $ . , , Hash:: check $user- > getAuthPassword() $credentials ['password']. true false, , .
, retrieveByCredentials() , Authenticatable).
:
<?php
namespace App\Authentication;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\UserProvider as IlluminateUserProvider;
use GuzzleHttp\Client;
use function GuzzleHttp\json_encode;
use function GuzzleHttp\json_decode;
use Illuminate\Support\Facades\Log;
class UserProvider implements IlluminateUserProvider
{
public function retrieveById($identifier)
{
\Log::info('retrieveById START');
}
public function retrieveByToken($identifier, $token)
{
\Log::info('retrieveByToken START');
}
public function updateRememberToken(Authenticatable $user, $token)
{
\Log::info('updateRememberToken START');
}
public function retrieveByCredentials(array $credentials) {
\Log::info('retrieveByCredentials START');
\Log::info('INSERTED USER CREDENTIAL: '.$credentials['email'] . ' ' .$credentials['password']);
$client = new Client();
$response = $client->get('http://localhost:8080/Extranet/login',
[
'auth' => [
'nobili.andrea@gmail.com',
'pswd'
]
]);
$dettagliLogin = json_decode($response->getBody());
\Log::info('response: '.(json_encode($dettagliLogin)));
$user = new User('Pippo', 'pippo@google.com', true);
\Log::info('USER: '.(json_encode($user)));
return $user;
}
public function validateCredentials(Authenticatable $user, array $credentials)
{
\Log::info('validateCredentials START');
}
}
a ( , , JSON) -:
<?php
namespace App\Authentication;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Log;
class User implements Authenticatable {
private $username;
private $email;
private $enabled;
public function __construct($username, $email, $enabled)
{
$this->username = $username;
$this->email = $email;
$this->enabled = $enabled;
}
public function getAuthIdentifierName() {
}
public function getAuthIdentifier() {
}
public function getAuthPassword() {
}
public function getRememberToken() {
}
public function setRememberToken($value) {
}
public function getRememberTokenName() {
}
public function getUsername()
{
return $this->username;
}
public function setUsername($username)
{
$this->username = $username;
}
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
public function getEnabled()
{
return $this->enabled;
}
public function setEnabled($enabled)
{
$this->enabled = $enabled;
}
}
, retrieveByCredentials() , , :
retrieveByCredentials() , , message: .

, , Laravel ( ), .
? , retrieveByCredentials() .
? ? ?