我有一个 Symfony 5.4,在开发环境下(docker),登录功能正常。但是当我在生产环境下通过 docker 尝试相同的登录时,出现以下问题:
{"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>
action
(action="{{ path('login') }}"
)。 - zizoujab