JWT Framework
Search…
Events
How to use Symfony events
With the version 2.0 of the Symfony Bundle, you will be able to listen or subscribe to events.
All events can be found in the class Jose\Bundle\JoseFramework\Event\Events.
  • JWS:
    • Events::JWS_BUILT_SUCCESS
    • Events::JWS_BUILT_FAILURE
    • Events::JWS_VERIFICATION_SUCCESS
    • Events::JWS_VERIFICATION_FAILURE
    • Events::JWS_LOADING_SUCCESS
    • Events::JWS_LOADING_FAILURE
  • JWE:
    • Events::JWE_BUILT_SUCCESS
    • Events::JWE_BUILT_FAILURE
    • Events::JWE_DECRYPTION_SUCCESS
    • Events::JWE_DECRYPTION_FAILURE
    • Events::JWE_LOADING_SUCCESS
    • Events::JWE_LOADING_FAILURE
  • Nested Tokens:
    • Events::NESTED_TOKEN_ISSUED Events::NESTED_TOKEN_LOADING_SUCCESS Events::NESTED_TOKEN_LOADING_FAILURE
  • Checked Header:
    • Events::HEADER_CHECK_SUCCESS
    • Events::HEADER_CHECK_FAILURE
  • Checked Claim:
    • Events::CLAIM_CHECK_SUCCESS
    • Events::CLAIM_CHECK_FAILURE

Example:

App\EventSubscriber\JwsSubscriber.php
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\EventSubscriber;
6
7
use Jose\Bundle\JoseFramework\Event\Events;
8
use Jose\Bundle\JoseFramework\Event\JWSBuiltSuccessEvent;
9
use Jose\Bundle\JoseFramework\Event\JWSVerificationFailureEvent;
10
use Jose\Bundle\JoseFramework\Event\JWSVerificationSuccessEvent;
11
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
12
13
class JwsSubscriber implements EventSubscriberInterface
14
{
15
public static function getSubscribedEvents()
16
{
17
return [
18
Events::JWS_VERIFICATION_SUCCESS => ['onJwsVerificationSuccess'],
19
Events::JWS_VERIFICATION_FAILURE => ['onJwsVerificationFailure'],
20
Events::JWS_BUILT_SUCCESS => ['onJwsBuiltSuccess'],
21
Events::JWS_BUILT_FAILURE => ['onJwsBuiltFailure'],
22
];
23
}
24
25
public function onJwsVerificationSuccess(JWSVerificationSuccessEvent $event): void
26
{
27
// Do something here
28
}
29
30
public function onJwsVerificationFailure(JWSVerificationFailureEvent $event): void
31
{
32
// Do something here
33
}
34
35
public function onJwsBuiltSuccess(JWSBuiltSuccessEvent $event): void
36
{
37
// Do something here
38
}
39
40
public function onJwsBuiltFailure(JWSBuiltFailureEvent $event): void
41
{
42
// Do something here
43
}
44
}
Copied!
Last modified 2yr ago
Copy link
Contents
Example: