【发布时间】:2021-12-13 19:48:56
【问题描述】:
我有一个 Symfony 5.4,在开发环境(docker)中登录工作正常。但是当我通过 docker on prod 尝试相同的登录时,我有:
{"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') }}")