私はデシベルからユーザーを取得し、彼女をログインしようとloginAction
を持っている。ログイン後、Symfony、UsernamePasswordTokenクラスのトークンに対して認証プロバイダが見つかりませんでしたか?
「メイン」ファイアウォールルールはむしろsecure_area
ものより使用されているようです。私が得るために:
No Authentication Provider found for token of class "Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken"
i 'がメインの' ファイアウォールルールに
guard:
authenticators:
- token_authenticator
を追加した場合、エラーが表示されなくなりますが、token_authenticator
が引き継ぎ、私はすべてのルート上Authentication Required
を取得
ログイン後に$token
またはsession
をダンプすると、そこに自分のユーザーが表示されます。
私は間違って何をしていますか?ここ
public function loginAction(Request $request)
{
if ($request->isMethod('POST')) {
$userManager = $this->container->get('entity.user');
$hasEmail = $this->getDoctrine()->getRepository('AppBundle:User')->findOneBy([
'email' => $request->request->get('email'),
'password' => $request->request->get('password'),
]);
// if credentials found
if ($hasEmail) {
// login the user
$token = new UsernamePasswordToken($hasEmail, $hasEmail->getPassword(), "secure_area", $hasEmail->getRoles());
$this->get("security.token_storage")->setToken($token);
$this->get('session')->set('_security_secure_area', serialize($token));
//$event = new InteractiveLoginEvent($request, $token);
//$this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
} else {
$error = 'invalid credentials';
}
}
return [];
}
は私のファイアウォールのルールです:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
provider: db_provider
main:
anonymous: ~
secure_area:
pattern: ^/
anonymous: ~
logout:
path: /logout
target:/
guard:
authenticators:
- token_authenticator