Fosuserbundle Ajax Login With Symfony2 (routing)
I'm trying to make the AJAX authentication work with FOSUserBundle. I have created an Handler directory with a AuthenticationHandler class :
Solution 1:
First Issue: You are sending an invalid CSRF token. In Symfony 2.3 you could generate it using {{ csrf_token('authenticate') }} inside the template's input's value.
Second issue: Do not overwrite the route, simply use the original route: fos_user_security_check.
In general: if you use an AuthenticationSuccessHandler extending Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler your method could look something like this:
publicfunctiononAuthenticationSuccess(Request $request, TokenInterface $token)
{
if ($request->isXmlHttpRequest()) {
returnnew JsonResponse(array('success' => true));
}
returnparent::onAuthenticationSuccess($request, $token);
}
Do something similar for an AuthenticationFailureHandler extending Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler.
Post a Comment for "Fosuserbundle Ajax Login With Symfony2 (routing)"