I have a Symfony 5.4, in dev env (docker) the login works fine. But when I try the same login via docker on prod, i have:
{"message":"Invalid CSRF token."}
AppAuthenticator.php
public function authenticate(Request $request): Passport
{
.....
return new Passport(
new UserBadge($credentials['username']),
new PasswordCredentials($credentials['password']),
[new CsrfTokenBadge('authenticate', $credentials['csrf_token'])]
);
}
security.yaml
security:
firewalls:
main:
form_login:
login_path: _security_login
check_path: _security_check
enable_csrf: true
login.html.twig
<form method="post">
....
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}" />
</form>
Make sure $credentials['csrf_token'] is equal to $request->request->get('_csrf_token')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.