I am writing an ajax application with ajax authentication, and now I started using the symfony security component in silex to handle authentication / authorization.
Performing a simple test with a simple configuration, I go to the protected zone using a firewall and the answer I get is redirected to the /login page, but what I need in my application is answer 401 with possible additional information (in headers or json body) on how to log in.
$app['security.firewalls'] = [ 'api' => [ 'pattern' => '^/api', 'logout' => ['logout_path'=>'/auth/logout'], 'users' => $app->share(function(Application $app) { return new MyUserProvider(); }) ] ];
EDIT: I have a hint, but I'm not sure how to use it. Implementing an entry point using AuthenticationEntryPointInterface I can tell the api how to respond to unauthorized requests and provide the user with the instructions necessary for authentication. This may be my 401 answer with login instructions.
security authentication php symfony silex
olanod
source share