0

私の要件では、ユーザーは URL が記載されたメールを受け取ります。ユーザーがクリックすると、認証プロセスを介してその URL に移動します。

したがって、クリックした URL にユーザーをリダイレクトするには、ここで説明した方法 (リダイレクト時にパラメーターを渡す) を使用しています。ここでは、リダイレクト URL を次のようなパラメーターとして渡す予定です。

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

security.ymlでキャプチャし$url=$_GET['redirect'];、それに応じてリダイレクトを提供します。

私のクエリは、security.ymlにアタッチできるように、 内から現在の URL にアクセスするにはどうすればよいかということlogin_pathです。

私はこれにまったく慣れておらず、例/ドキュメントは非常に高く評価されています。:)

PS

認証は別のsymonfy2アプリケーション内で行われ、その時点でrefererコマンドがnullになるため使用できません。そのため、リダイレクト URL をパラメーターとして渡そうとしています。:)

4

1 に答える 1

2

エントリ ポイントと成功ハンドラを使用することをお勧めします。

security.yml:

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

SuccessHandler (ソース):

<?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;
    }
}

エントリ ポイント ( source ):

ユーザーがまったく認証されていない場合 (つまり、トークン ストレージにまだトークンがない場合)、ファイアウォールのエントリ ポイントが呼び出されて、認証プロセスが「開始」されます。エントリ ポイントは、メソッドが 1 つだけある AuthenticationEntryPointInterface を実装する必要があります: start() ...

于 2015-01-13T07:50:53.600 に答える