i am trying to prevent redirect to login page when user is trying to access a page without token, i have single page app and i am only putting the ajax requests under firewall and when a user is doing ajax without token i want the ajax to return forbidden exception so i will be able to catch it in client side
currently the ajax returns "Found" since the request is being redirected to the login page
i haven't found a solution in cookbook so far i dont want to use api tokens, only send an exception instead of redirecting to login
You need to define an
entry_point
to your firewall in order for you to return unauthorized response. Information about entry points can be found in the documentation here. I will copy the paragraph in case of future requests here.So in order for you to do that, you have to create a class that is going to be defined as a service.
It should look like this:
And in your
services.yml
fileAnd finally pass the service id
service.entry_point
to yourentry_point
option infirewall
section ofsecurity.yml
file.This should do the trick.