- Плагин аутентификации Cakephp 3, URL-адрес входа не совпадает
- Вход для аутентификации Cakephp4 не работает
Код: Выделить всё
Application.phpКод: Выделить всё
public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
{
$login_url = \Cake\Routing\Router::url('/users/login');
//dd($login_url) outputs /my_app/users/login
$service = new AuthenticationService([
'unauthenticatedRedirect' => $login_url,
'queryParam' => 'redirect',
]);
//
$service->loadAuthenticator('Authentication.Session');
$service->loadAuthenticator('Authentication.Environment', [
'loginUrl' => $login_url,
'fields' => [
// Choose which environment variables exposed by your
// authentication provider are used to authenticate
// in your application.
'HTTP_SAML_EMAIL',
],
]);
//
$service->loadIdentifier('Authentication.Token', [
'tokenField' => 'email',
'dataField' => 'HTTP_SAML_EMAIL',
'resolver' => [
'className' => 'Authentication.Orm',
'userModel' => 'Users',
'finder' => 'authenticatedUser', //check Users table for custom finder
],
]);
return $service;
}
Код: Выделить всё
Users.loginКод: Выделить всё
public function login()
{
/*
FAILURE_CREDENTIALS_MISSING - no headers
FAILURE_IDENTITY_NOT_FOUND - user not found, must be added
SUCCESS - all good
*/
//get auth status
$status = $this->Authentication->getResult()->getStatus();
if($status == 'SUCCESS') //user found, must update
{
//...
$target = $this->Authentication->getLoginRedirect() ?? \Cake\Routing\Router::url(['controller'=>'Users', 'action'=>'workspace']);
//debug("a:". $target);
$this->Flash->success(__('You have successfully logged in'));
return $this->redirect($target);
}
elseif($status == 'FAILURE_IDENTITY_NOT_FOUND') //user not found, must add
{
//...
$target = $this->Authentication->getLoginRedirect() ?? \Cake\Routing\Router::url('/users/workspace');
//debug("b:". $target);
$this->Flash->success(__('You have successfully logged in'));
return $this->redirect($target);
}
elseif($status == 'FAILURE_CREDENTIALS_MISSING')
{
throw new \Cake\Core\Exception\CakeException(__('Authentication error, missing headers. Please contact system administrators.'), 403);
}
else
{
//THIS IS WHERE WE'RE AT NOW
debug($this->Authentication->getResult());
debug($this->request);
throw new \Cake\Core\Exception\CakeException(__('Uncaught exception during authentication. Please contact system administrators.'), 500);
}
}
Трассировка сети:
- (301)
Код: Выделить всё
/my_app - (200) (дополнительная косая черта??)
Код: Выделить всё
/my_app/ - (500) (ожидается, $this->Authentication->getResult()->getStatus() — FAILURE_OTHER)
Код: Выделить всё
/my_app/
Редактировать №3
Может быть, дело в моих маршрутах?
Код: Выделить всё
$routes->scope('/',
$builder->connect('/', ['controller' => 'Users', 'action' => 'login'], ['name' => 'app']);
$builder->fallbacks();
});
Подробнее здесь: https://stackoverflow.com/questions/784 ... sers-login
Мобильная версия