File tree Expand file tree Collapse file tree 2 files changed +46
-3
lines changed
src/AppBundle/Event/Listener Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -4,9 +4,13 @@ parameters:
4
4
# parameter_name: value
5
5
6
6
services :
7
- # service_name:
8
- # class: AppBundle\Directory\ClassName
9
- # arguments: ["@another_service_name", "plain_value", "%parameter_name%"]
7
+
8
+ event.jwt_created_listener :
9
+ class : AppBundle\Event\Listener\JWTCreatedListener
10
+ arguments :
11
+ - " @security.token_storage"
12
+ tags :
13
+ - { name: kernel.event_listener, event: lexik_jwt_authentication.on_jwt_created, method: onJWTCreated }
10
14
11
15
user.mailer.rest :
12
16
class : AppBundle\Mailer\RestMailer
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace AppBundle \Event \Listener ;
4
+
5
+ use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
6
+ use Lexik \Bundle \JWTAuthenticationBundle \Event \JWTCreatedEvent ;
7
+
8
+ class JWTCreatedListener
9
+ {
10
+ /**
11
+ * @var TokenStorageInterface
12
+ */
13
+ private $ tokenStorage ;
14
+
15
+ /**
16
+ * @param TokenStorageInterface $tokenStorage
17
+ */
18
+ public function __construct ( TokenStorageInterface $ tokenStorage )
19
+ {
20
+ $ this ->tokenStorage = $ tokenStorage ;
21
+ }
22
+
23
+ /**
24
+ * Adds additional data to the generated JWT
25
+ *
26
+ * @param JWTCreatedEvent $event
27
+ *
28
+ * @return void
29
+ */
30
+ public function onJWTCreated (JWTCreatedEvent $ event )
31
+ {
32
+ $ payload = $ event ->getData ();
33
+
34
+ // add new data
35
+ $ payload ['userId ' ] = $ this ->tokenStorage ->getToken ()->getUser ()->getId ();
36
+
37
+ $ event ->setData ($ payload );
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments