my problem is simple. I'm trying to create admin account with authentication by this simple way:
$ symfony composer req security
$ symfony console make:user Admin
I'm doing whole configuration in the files from the tutorial (https://symfony.com/doc/current/the-fast-track/pl/15-security.html) and:
$ symfony console security:encode-password
$ symfony run psql -c "INSERT INTO admin (id, username, roles, password) \
VALUES (nextval('admin_id_seq'), 'admin', '[\"ROLE_ADMIN\"]', \ '\$2y$13$WbjbWP7f3KrRbO0XKkECmuOMInik.xPS5bWgE72dgslRFmMLMBuRq')"
The command symfony run psql -c doesn't work properly on my Windows10, so I created same thing in the terminal by psql psql -h localhost -U postgres:
INSERT INTO admin (id, username, roles, password)
VALUES ('1', 'admin', '["ROLE_ADMIN"]', '$2y$13$ELXmuFKvzmE4x9crO58LmOp4CEle1578nEGhriJcZJLemKgB9qlsO');
New fields have been created in the database, but I still cannot login in to the easyAdmin panel, and I haven't idea what I am doing wrong.
Security.yaml
security:
enable_authenticator_manager: true
password_hashers:
App\Entity\Admin:
algorithm: auto
providers:
app_user_provider:
entity:
class: App\Entity\Admin
property: username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
lazy: true
provider: app_user_provider
custom_authenticator: App\Security\AppAuthenticator
logout:
path: app_logout
- { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
AppAuthenticator
public function authenticate(Request $request): PassportInterface
{
$username = $request->request->get('username', '');
$request->getSession()->set(Security::LAST_USERNAME, $username);
return new Passport(
new UserBadge($username),
new PasswordCredentials($request->request->get('password', '')),
[
new CsrfTokenBadge('authenticate', $request->get('_csrf_token')),
]
);
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
{
if ($targetPath = $this->getTargetPath($request->getSession(), $firewallName)) {
return new RedirectResponse($targetPath);
}
return new RedirectResponse($this->urlGenerator->generate('admin'));
}
