Get current url in security.yml

In my request, the user receives an email with the URL, as soon as he clicks, the user will be moved to the URL through the authentication process.

So, to redirect the user to the specified URL, I use the method mentioned here ( Transfer parameters when redirecting ), where I intend to pass the redirect URL as a parameter, for example

login_path: %accounts_host%/signin?redirect=%need_current_url_here%

within security.ymland fix as such $url=$_GET['redirect'];and ensure appropriate redirection.

My request is: how can I access the current url from security.ymlso that I can attach it to login_path.

I am new to this and any example / document is much appreciated. :)

PS

Authentication is performed in another symonfy2 application, after which I cannot use the command refererbecause it will be empty. This is why I am trying to pass you the redirect URL as a parameter. :)

0
source share
1 answer

I would suggest using an entry point and a success handler.

security.yml:

firewalls:            # Required
    # Examples:
    somename:
        entry_point: some.service.id
        ...
        form_login:
            ...
            success_handler: some.service.id

SuccessHandler ( source ):

<?php
namespace StatSidekick\UserBundle\Handler;

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
use Symfony\Component\Security\Http\HttpUtils;

class AuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler {

    public function __construct( HttpUtils $httpUtils, array $options ) {
        parent::__construct( $httpUtils, $options );
    }

    public function onAuthenticationSuccess( Request $request, TokenInterface $token ) {
        // Create if necessary a redirect response otherwise use the parent one with
        // $response = parent::onAuthenticationSuccess( $request, $token );

        return $response;
    }
}

Entry Point ( Source ):

( , ), "" . AuthenticationEntryPointInterface, : start()...

+2

All Articles