Skip to content

Events

With 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

Info

Since 4.3, the services that dispatch these events are decorators wrapping the plain services, where they used to be subclasses. They keep their class names, their service ids and their behaviour: no configuration change is needed and the events you listen to are unchanged.

One thing did change for the better: the event dispatching verifier and decrypter used to drop the callable the loaders pass to observe the keys discarded along the way, so the reason of a failure was lost as soon as the bundle services were used. They forward it now.

Example:

App\EventSubscriber\JwsSubscriber.php
<?php

declare(strict_types=1);

namespace App\EventSubscriber;

use Jose\Bundle\JoseFramework\Event\Events;
use Jose\Bundle\JoseFramework\Event\JWSBuiltSuccessEvent;
use Jose\Bundle\JoseFramework\Event\JWSVerificationFailureEvent;
use Jose\Bundle\JoseFramework\Event\JWSVerificationSuccessEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class JwsSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            Events::JWS_VERIFICATION_SUCCESS => ['onJwsVerificationSuccess'],
            Events::JWS_VERIFICATION_FAILURE => ['onJwsVerificationFailure'],
            Events::JWS_BUILT_SUCCESS => ['onJwsBuiltSuccess'],
            Events::JWS_BUILT_FAILURE => ['onJwsBuiltFailure'],
        ];
    }

    public function onJwsVerificationSuccess(JWSVerificationSuccessEvent $event): void
    {
        // Do something here
    }

    public function onJwsVerificationFailure(JWSVerificationFailureEvent $event): void
    {
        // Do something here
    }

    public function onJwsBuiltSuccess(JWSBuiltSuccessEvent $event): void
    {
        // Do something here
    }

    public function onJwsBuiltFailure(JWSBuiltFailureEvent $event): void
    {
        // Do something here
    }
}