Skip to content

[Security] Add documentation for the optional $options params accepted by createLoginLink (LoginLinkHandlerInterface) #16385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion security/custom_authenticator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ would initialize the passport like this::
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;

class LoginAuthenticator extends AbstractAuthenticator
{
Expand Down
34 changes: 32 additions & 2 deletions security/login_link.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ intercept requests to this route:
throw new \LogicException('This code should never be reached');
}
}

.. code-block:: php-attributes

// src/Controller/SecurityController.php
namespace App\Controller;

Expand Down Expand Up @@ -804,3 +804,33 @@ features such as the locale used to generate the link::

// ...
}


The ``createLoginLink()`` method accepts a third optional argument to pass an
``options`` array. There are three keys to consider: route_name, lifetime and parameters.
$options['route_name'] will override the global route_name value and $options['lifetime'] will override the lifetime global value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention what the global route_name and lifetime values are? Maybe give an example of why might want to override them?

$options['parameters'] accepts and array of name/values to pass to the internal router and to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$options['parameters'] accepts and array of name/values to pass to the internal router and to
$options['parameters'] accepts an array of name/values to pass to the internal router and to

append to the login link query parameters.::

// ...
class SecurityController extends AbstractController
{
/** @Route("/login", name="login") */
public function requestLoginLink(LoginLinkHandlerInterface $loginLinkHandler, Request $request)
{
// ...
$options['route_name'] = 'another_login_check_url';
$options['lifetime'] = 1200;
$options['parameters'] = [
'redirection_uri' => 'custom_securized_uri_to_redirect_after_successful_login',
'country' => 'ES'
// ...
];

$loginLinkDetails = $loginLinkHandler->createLoginLink($user, null, $options);
$loginLink = $loginLinkDetails->getUrl();
// ...
}
// ...
}