diff --git a/Classes/Domain/Service/Neos/NeosRedirectTargetService.php b/Classes/Domain/Service/Neos/NeosRedirectTargetService.php index edb14a8..30f66ed 100644 --- a/Classes/Domain/Service/Neos/NeosRedirectTargetService.php +++ b/Classes/Domain/Service/Neos/NeosRedirectTargetService.php @@ -54,7 +54,10 @@ public function onAuthenticationSuccess(ControllerContext $controllerContext, Ac // Neos only logic (configuration at node or via TS) /** @var ActionRequest $actionRequest */ $actionRequest = $controllerContext->getRequest(); - if ($actionRequest->getInternalArgument('__redirectAfterLogin')) { + + if ($actionRequest->getHttpRequest()->hasArgument('forwardUrl') && strlen($actionRequest->getHttpRequest()->getArgument('forwardUrl'))) { + return $this->sanitizeForwardUrl($actionRequest->getHttpRequest()->getArgument('forwardUrl')); + } elseif ($actionRequest->getInternalArgument('__redirectAfterLogin')) { return $this->getNodeLinkingService() ->createNodeUri($controllerContext, $actionRequest->getInternalArgument('__redirectAfterLogin')); } @@ -98,4 +101,12 @@ protected function getNodeLinkingService() { return $this->objectManager->get(LinkingService::class); } + + /** + * @param string $forwardUrl + * @return string + */ + protected function sanitizeForwardUrl(string $forwardUrl): string { + return filter_var($forwardUrl, FILTER_SANITIZE_URL); + } } diff --git a/README.md b/README.md index c0e06fa..d1bed48 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,16 @@ loginform = Sandstorm.UserManagement:LoginForm { } ``` +### Via url parameter +When using the package within Neos, you can also use an url parameter to provide a redirect target, e.g. the site where +the user clicked on login. To do so, just append the parameter `forwardUrl` to your url. This url will be sanitized by +removing all characters which are not allowed in urls and then will be used before checking the noe properties. + +URL example: +``` +http://localhost/login.html?forwardUrl=http%3A//localhost/editor%3FeditMode%3D%22true%22 +``` + ### Via custom RedirectTargetService If redirecting to a specific controller method is still not enough for you, you can simply roll your own implementation of the `RedirectTargetServiceInterface`. Just add the implementation within your own package and add the following lines to your `Objects.yaml`.