Closed
Description
Using the new Guard component I am redirecting the user to a page like /user/{username}. The problem is I cannot access the user token in getDefaultSuccessRedirectUrl
. I am proposing that the $request
and $token
get passed to getDefaultSuccessRedirectUrl
Without the token I have to adjust my authenticator like this
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
// if the user hit a secure page and start() was called, this was
// the URL they were on, and probably where you want to redirect to
$targetPath = $request->getSession()->get('_security.'.$providerKey.'.target_path');
if (!$targetPath) {
$targetPath = $this->container->get('router')
->generate('app_user_index', ['username' => $token->getUsername()]);
}
return new RedirectResponse($targetPath);
}
protected function getDefaultSuccessRedirectUrl()
{
// nothing
}
This is not so good b/c I have to define getDefaultSuccessRedirectUrl which will never be used. Perhaps it would be better if the definition was more like this protected function getDefaultSuccessRedirectUrl(Request $request, TokenInterface $token)
Or maybe getDefaultSuccessRedirectUrl
should not be defined as an abstract method.