8000 [Security] Custom Authenticator: Adding info about session · ThomasLandauer/symfony-docs@4843b34 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4843b34

Browse files
[Security] Custom Authenticator: Adding info about session
Page: https://symfony.com/doc/5.x/security/custom_authenticator.html This line was really missing on this page: ```php $request->getSession()->set(SecurityRequestAttributes::AUTHENTICATION_ERROR, $exception); ``` I hope the code block formatting (inside this list) works. If not, the list could be changed to sub-headings. In preparation of this, I also moved the box about which class to extend upwards (to the other info about extending).
1 parent bfdf56e commit 4843b34

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

security/custom_authenticator.rst

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ cases, you must create and use your own authenticator.
99

1010
Authenticators should implement the
1111
:class:`Symfony\\Component\\Security\\Http\\Authenticator\\AuthenticatorInterface`.
12+
13+
.. tip::
14+
15+
If your login method is interactive, which means that the user actively
16+
logged into your application, you may want your authenticator to implement the
17+
:class:`Symfony\\Component\\Security\\Http\\Authenticator\\InteractiveAuthenticatorInterface`
18+
so that it dispatches an
19+
:class:`Symfony\\Component\\Security\\Http\\Event\\InteractiveLoginEvent`
20+
1221
You can also extend
1322
:class:`Symfony\\Component\\Security\\Http\\Authenticator\\AbstractAuthenticator`,
1423
which has a default implementation for the ``createToken()``
@@ -176,7 +185,12 @@ can define what happens in these cases:
176185

177186
If ``null`` is returned, the request continues like normal. This is
178187
useful for e.g. login forms, where the login controller is run again
179-
with the login errors.
188+
with the login errors. In order to access the login error in the controller
189+
with ``$authenticationUtils->getLastAuthenticationError()``, you need to
190+
store it in the session now::
191+
192+
use Symfony\Component\Security\Http\SecurityRequestAttributes;
193+
$request->getSession()->set(SecurityRequestAttributes::AUTHENTICATION_ERROR, $exception);
180194

181195
If you're using :ref:`login throttling <security-login-throttling>`,
182196
you can check if ``$exception`` is an instance of
@@ -190,13 +204,6 @@ can define what happens in these cases:
190204
above. Use :class:`Symfony\\Component\\Security\\Core\\Exception\\CustomUserMessageAuthenticationException`
191205
if you want to set custom error messages.
192206

193-
.. tip::
194-
195-
If your login method is interactive, which means that the user actively
196-
logged into your application, you may want your authenticator to implement the
197-
:class:`Symfony\\Component\\Security\\Http\\Authenticator\\InteractiveAuthenticatorInterface`
198-
so that it dispatches an
199-
:class:`Symfony\\Component\\Security\\Http\\Event\\InteractiveLoginEvent`
200207

201208
.. _security-passport:
202209

0 commit comments

Comments
 (0)
0