A desktop application interacts with my website running on symfony2 and requires response in json, beginning with login success/failure. Using http_basic and providers if the login is correct everything works fine, but Im not able to send the json response.
And if the login is incorrect it re-prompts the username and password dialog. How can I stop at the first failure attempt and send the json response
{
'message':'invalid password/username'
}
security.yml
app:
pattern: ^/app.*
logout: true
security: true
http_basic:
provider: webservice
providers:
fos_userbundle:
id: fos_user.user_manager
webservice:
id: my_provider
config.yml
my_provider:
parent: doctrine.odm.mongodb.security.user.provider
arguments: [ Se\PPBundle\Document\User, username]
tl;dr
I want to respond with json on login.
From the looks of it you are using the FOS User bundle to handle your authentication. If this is the case you will need to overload the FOS Security controller login action. Change the logic in there to send a difference response on fail instead of just rendering the view with the errors. You will also need to customize the routing for the login. Something to the effect of:
Note the _format:json this will return your responses as “application/json” you will still need to json_encode the return