5

The isssue I am trying to address is to automatically redirect my application to the user entered url after login. Since I have a centralized authentication server I cant user 'HTTP_REFERER' as it always returns null when am being transferred to the authentication server.

My solution is to use the security.yml in my application server to pass the redirection url as url parameter. I have implemented that as follows,

parameters.php

$container->setParameter('referer', $_SERVER['REQUEST_URI']);

security.yml

    secured_area:
        pattern: ^/
        stateless: true
        form_login: 
            login_path: %accounts_host%/signin?referer=%referer%
        simple_preauth:
            authenticator: app.security.authenticator 

But my issue is that the referer parameter in security.yml is always static. It always gives the first application url I type in. Lets say if i type www.appserver.com/product/1, the next time if I type in www.appserver.com/product/200 the referer will always return www.appserver.com/product/1 in the authenitcation server.

However, If I do a print_r($_SERVER['REQUEST_URI']); exit(); in the parameters.php the value changes for my each request.

I was at this for quite some time and I am very lost at this point. Any help on getting this referer value dynamically on the security.yml would be really appreciated. thanks :)

Hasitha Shan
  • 2,900
  • 6
  • 42
  • 83
  • 1
    have a look at this post http://stackoverflow.com/questions/16079592/how-does-symfony2-redirect-to-requested-page-after-login – Shairyar Jan 23 '15 at 05:29
  • @Baig thanks for the reference! will take a look at it – Hasitha Shan Jan 24 '15 at 14:55
  • possible duplicate of [Get current url within security.yml](http://stackoverflow.com/questions/27898039/get-current-url-within-security-yml) – CSchulz Jan 26 '15 at 13:04
  • FYI, in production environments, your parameter will be cached. Which is why it's the first URL you go to. You'll probably want to create your own success handler instead. This may help: http://stackoverflow.com/questions/15918617/symfony2-extending-defaultauthenticationsuccesshandler – Nick Apr 26 '16 at 15:08

0 Answers0