php - Symfony: Retrieve user from a different firewall than the firewall being used in the current request

I have a Symfony application that is utilising 2 firewalls. I have logged into both within the same session. When I access a backend firewall page, I can access the user provider object (in my case an Admin entity) but I can't work out how to get access to the frontend firewall's user provider object too from the backend route (so in this case a Customer entity).
An example of a use case is as follows - I have built a CMS style application and I am logged into the backend as and ADMIN to complete some work on specific pages related to the frontend of the website. I then change to the frontend of the website and login as a CUSTOMER to test my work (NOTE: at this stage, I am actually still logged into the backend of the website, but because I am not using an "^/admin" route, it returns to me the CUSTOMER user provider). Now, from this frontend page, I would like to get the ADMIN entity that is logged into the backend of the website so I can check if some frontend page editing can be completed on the page WHILE I am still logged in as the CUSTOMER.
My firewalls look as follows:
security:
firewalls:
backend:
pattern: ^/admin
anonymous: lazy
provider: backend_user_provider
guard:
authenticators:
- App\Security\BackendAuthenticator
logout:
path: backend_logout
frontend:
anonymous: lazy
provider: frontend_user_provider
guard:
authenticators:
- App\Security\FrontendAuthenticator
logout:
path: frontend_logout
I cannot find anything on the web to explain how to do this. I have found info on the following, but none of them relate to what I am wanting:
- Programmatically authenticating to a different firewall
- Sharing context
Answer
Solution:
It is not the right way to use firewalls.
All you need is to use just one firewall in this case and you will not have any problems.
Answer
Solution:
According to the docs you can share auth between firewalls:
Can I Share Authentication Between Firewalls? Yes, but only with some configuration. If you’re using multiple firewalls and you authenticate against one firewall, you will not be authenticated against any other firewalls automatically. Different firewalls are like different security systems. To do this you have to explicitly specify the same Firewall Context for different firewalls. But usually for most applications, having one main firewall is enough.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to a member function store() on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.