K
K
Konstantin2015-10-15 03:04:10
symfony
Konstantin, 2015-10-15 03:04:10

How to get _security.default.target_path in controller?

Hello.
I also have social login links on the login page, which can be passed some internal path so that after a redirect from the social network, the user returns to the URI from which he got to the login.
Inside Symfony, the _security.default.target_path parameter in the session is responsible for this. The referrer is not suitable, because it contains not always correct data (for example, I go from a publicly available product /good/{good_id}page to a payment page /good/{good_id}/buythat already requires authentication, being not logged in, and I get a 302 redirect to /signin. In this case, the referrer will contain /good/{good_id}, and not expected /good/{good_id}/buy)..
In this case, the session contains the correct parameter, which I would like to get.
Of course, you can do something like

$target = $this->get('session')->get('_security.default.target_path', '/')
, but you yourself understand the reliability and correctness of this decision.
Maybe there is a legal way to refer to this value? Well, I would like to avoid writing my own AuthenticationListener, since it will simply duplicate the functionality of the built-in one.
UPD : I also realized that default in this case is also the name of the current firewall, that is, it is even more wrong to be tied to the name of a parameter in the session.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question