0

在我的要求中,用户会收到一封带有 url 的电子邮件,一旦他单击,用户将通过身份验证过程导航到该 url。

因此,要将用户重定向到单击的 url,我使用的是此处提到的方法(重定向时传递参数),我打算将重定向 url 作为参数传递,例如

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

security.yml和捕获中,$url=$_GET['redirect'];并相应地提供重定向。

我的查询是如何从 中访问当前 url,security.yml以便将其附加到login_path.

我对此很陌生,非常感谢任何示例/文档。:)

附言

身份验证是在另一个 symonfy2 应用程序中完成的,此时我不能使用referer命令,因为它将为空。这就是为什么我试图将重定向 url 作为参数传递。:)

4

1 回答 1

2

I would suggest to use 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):

When the user is not authenticated at all (i.e. when the token storage has no token yet), the firewall's entry point will be called to "start" the authentication process. An entry point should implement AuthenticationEntryPointInterface, which has only one method: start() ...

于 2015-01-13T07:50:53.600 回答