Мне нужно настроить процедуру входа в Laravel 6.
Данные пользователей находятся в другой системе (не Laravel).
Теперь пользователь должен войти в проект laravel с помощьюучетные данные пользователя из другой системы. Это будет сделано путем вызова его API.
В проекте Laravel нет пользователей, хранящихся в базе данных. Все пользовательские данные должны быть получены из API.
Я пытался сделать это с помощью настраиваемой защиты, которая наследуется от защиты сеанса.
<?php
// AuthServiceProvider.php
namespace App\Providers;
use App\Auth\Guards\CosGuard;
use Illuminate\Container\Container;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Auth;
use Illuminate\Auth\EloquentUserProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
// 'App\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
Auth::extend('cos', function (Container $app) {
$provider = new EloquentUserProvider($app['hash'], config('auth.providers.users.model'));
return new CosGuard('cos', $provider, app()->make('session.store'), $app['request']);
});
$this->registerPolicies();
}
}
<?php
// CosGuard.php
namespace App\Auth\Guards;
use Illuminate\Auth\SessionGuard;
use App\User;
class CosGuard extends SessionGuard
{
/**
* Validate a user's credentials.
*
* @param array $credentials
* @return bool
*/
public function validate(array $credentials = [])
{
return true;
}
/**
* Attempt to authenticate a user using the given credentials.
*
* @param array $credentials
* @param bool $remember
* @return bool
*/
public function attempt(array $credentials = [], $remember = false)
{
$this->fireAttemptEvent($credentials, $remember);
$user = new User;
$user->id = 1;
$user->name = 'John';
$user->email = 'john@doe.com';
if ($user) {
$this->login($user, $remember);
return true;
}
// If the authentication attempt fails we will fire an event so that the user
// may be notified of any suspicious attempts to access their account from
// an unrecognized user. A developer may listen to this event as needed.
$this->fireFailedEvent($user, $credentials);
return false;
}
}
Вход в систему не работает. . Ничего не происходит.
Кто-нибудь может помочь?