I\'m writing an ajax application with ajax authentication and now I started using the symfony security component in silex to handle authentication/authorization.
Doing a
What you need is a AuthenticationEntryPoint handler. Simple example:
class AuthenticationEntryPoint implements AuthenticationEntryPointInterface {
/**
* Starts the authentication scheme.
*
* @param Request $request The request that resulted in an AuthenticationException
* @param AuthenticationException $authException The exception that started the authentication process
*
* @return Response
*/
public function start(Request $request, AuthenticationException $authException = null)
{
$array = array('success' => false);
$response = new Response(json_encode($array), 401);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
}
Register class as a service in services.xml file:
YourNameSpace\AuthenticationEntryPoint
and make a small change in security.yml file:
security:
firewalls:
somename:
entry_point: authentication_entry_point