-
Notifications
You must be signed in to change notification settings - Fork 23

Description
Hi everybody,
I'm having some troubles using this bundle to log JWT authentication events (using lexik/jwt-authentication-bundle).
Following the cookbook, I declared my custom resolvers
events:
- security.interactive_login
- security.authentication.failure
- security.authentication.success
- lexik_jwt_authentication.on_authentication_success
- lexik_jwt_authentication.on_authentication_failure
- lexik_jwt_authentication.on_jwt_created
- lexik_jwt_authentication.on_jwt_encoded
- lexik_jwt_authentication.on_jwt_decoded
- lexik_jwt_authentication.on_jwt_authenticated
- lexik_jwt_authentication.on_jwt_invalid
- lexik_jwt_authentication.on_jwt_not_found
- lexik_jwt_authentication.on_jwt_expired
custom_resolvers:
lexik_jwt_authentication.on_authentication_success: app.jwt_event_resolver
lexik_jwt_authentication.on_authentication_failure: app.jwt_event_resolver
lexik_jwt_authentication.on_jwt_created: app.jwt_event_resolver
lexik_jwt_authentication.on_jwt_encoded: app.jwt_event_resolver
lexik_jwt_authentication.on_jwt_decoded: app.jwt_event_resolver
lexik_jwt_authentication.on_jwt_authenticated: app.jwt_event_resolver
lexik_jwt_authentication.on_jwt_invalid: app.jwt_event_resolver
lexik_jwt_authentication.on_jwt_not_found: app.jwt_event_resolver
lexik_jwt_authentication.on_jwt_expired: app.jwt_event_resolver
registered my service
app.jwt_event_resolver:
class: App\Resolver\JWTEventResolver
and implemented my class (still WIP, so I know that the description and infos are not really helpful right now)
<?php
namespace App\Resolver;
use Xiidea\EasyAuditBundle\Resolver\EventResolverInterface;
use Symfony\Component\EventDispatcher\Event;
class JWTEventResolver implements EventResolverInterface
{
public function getEventLogInfo(Event $event, $eventName)
{
return array(
'description'=>'JWT description',
'type'=>$eventName
);
}
}
I'm getting the following errors
TypeError: Argument 1 passed to Xiidea\EasyAuditBundle\Listener\LogEventsListener::resolveEventHandler() must be an instance of Symfony\Component\EventDispatcher\Event, instance of Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationFailureEvent given, called in /var/www/html/vendor/symfony/event-dispatcher/Debug/WrappedListener.php on line 126
TypeError: Argument 1 passed to Xiidea\EasyAuditBundle\Listener\LogEventsListener::resolveEventHandler() must be an instance of Symfony\Component\EventDispatcher\Event, instance of Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent given, called in /var/www/html/vendor/symfony/event-dispatcher/Debug/WrappedListener.php on line 126
Doing some reverse engeneering brught me to the fact that those event classes are all extensions of this base class of JWT namespace
<?php
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
use Symfony\Component\EventDispatcher\Event as BaseEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Contracts\EventDispatcher\Event as ContractsBaseEvent;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
if (is_subclass_of(EventDispatcher::class, EventDispatcherInterface::class)) {
class Event extends ContractsBaseEvent
{
}
} else {
class Event extends BaseEvent
{
}
}
In fact, if I "patch" this declaration forcing it to be extended from BaseEvent, it starts involving my custom dispatchers correctly
Is there a way to avoid this behaviour? I know it sounds like a Lexik problem, but I think it could involve any custom event using contracts and could be useful to provide an integration.