Skip to content

Commit 8680b94

Browse files
committed
[#14700] Minor rewording
1 parent 29f1436 commit 8680b94

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

security/login_link.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,12 @@ user create this POST request (e.g. by clicking a button)::
656656
{% endblock %}
657657

658658
Customizing the Success Handler
659-
...............................
659+
-------------------------------
660660

661-
To customize, how the success handler behaves, create your own ``AuthenticationSuccessHandler``::
661+
Sometimes, the default success handling does not fit your use-case (e.g.
662+
when you need to generate and return an API key). To customize how the
663+
success handler behaves, create your own
664+
:class:`Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface`::
662665

663666
// src/Security/Authentication/AuthenticationSuccessHandler.php
664667
namespace App\Security\Authentication;
@@ -672,16 +675,14 @@ To customize, how the success handler behaves, create your own ``AuthenticationS
672675
{
673676
public function onAuthenticationSuccess(Request $request, TokenInterface $token): JsonResponse
674677
{
675-
// Example use case: Create API token for Guard Authentication.
676-
$user = $token->getUser(); // Returns string|\Stringable|UserInterface - depends on your implementation.
677-
678+
$user = $token->getUser();
678679
$userApiToken = $user->getApiToken();
679680

680681
return new JsonResponse(['apiToken' => 'userApiToken']);
681682
}
682683
}
683684

684-
Modify the configuration and use your handler for the ``success_handler`` key:
685+
Then, configure this service ID as the ``success_handler``:
685686

686687
.. configuration-block::
687688

@@ -715,7 +716,7 @@ Modify the configuration and use your handler for the ``success_handler`` key:
715716
check-post-only="true"
716717
max-uses="1"
717718
lifetime="600"
718-
success_handler="App\Security\Authentication\AuthenticationSuccessHandler"
719+
success-handler="App\Security\Authentication\AuthenticationSuccessHandler"
719720
/>
720721
</firewall>
721722
</config>
@@ -724,14 +725,16 @@ Modify the configuration and use your handler for the ``success_handler`` key:
724725
.. code-block:: php
725726
726727
// config/packages/security.php
728+
use App\Security\Authentication\AuthenticationSuccessHandler;
729+
727730
$container->loadFromExtension('security', [
728731
'firewalls' => [
729732
'main' => [
730733
'login_link' => [
731734
'check_route' => 'login_check',
732735
'lifetime' => 600,
733736
'max_uses' => 1,
734-
'success_handler' => 'App\Security\Authentication\AuthenticationSuccessHandler',
737+
'success_handler' => AuthenticationSuccessHandler::class,
735738
],
736739
],
737740
],

0 commit comments

Comments
 (0)