Lexikjwtauthenticationbundle: Events::AUTHENTICATION_SUCCESS - Adding public data to the JWT response

Created on 12 Mar 2018  路  2Comments  路  Source: lexik/LexikJWTAuthenticationBundle

Hi,

i麓m trying to add a custom public data to the JWT response and when i follow the instructions for my symfony instalation i麓m getting the following message:

(2/2)聽FileLoaderLoadExceptionThe autoloader expected class "App\EventListener\AuthenticationEventListener" to be defined in file "/Users/fjugaldev/Sites/sftest/civination-backend/vendor/composer/../../src/EventListener/AuthenticationEventListener.php". The file was found but the class was not in it, the class name or namespace probably has a typo in /Users/fjugaldev/Sites/sftest/civination-backend/config/services.yaml (which is loaded in resource "/Users/fjugaldev/Sites/sftest/civination-backend/config/services.yaml").

My services.yml looks like:

acme_api.event.authentication_success_listener:
        class: AppBundle\EventListener\AuthenticationSuccessListener
        tags:
            - { name: kernel.event_listener, event: lexik_jwt_authentication.on_authentication_success, method: onAuthenticationSuccessResponse }

And the class for this service:

use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;

/**
 * @param AuthenticationSuccessEvent $event
 */
public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
{
    $data = $event->getData();
    $user = $event->getUser();

    if (!$user instanceof UserInterface) {
        return;
    }

    $data['data'] = array(
        'roles' => $user->getRoles(),
    );

    $event->setData($data);
}

I'm doing everything just like the documentation says.

The next thing i tried is to define the service like this:

App\EventListener\AuthenticationSuccessListener:
        tags:
            - { name: kernel.event_listener, event: lexik_jwt_authentication.on_authentication_success, method: onAuthenticationSuccessResponse }

But still throwing the same error. I麓m using Symfony 4.

Anybody has any idea?

Thanks

Most helpful comment

Hi,

Error says AuthenticationEventListener.php but service definition says AuthenticationSuccessListener, classname-filename mismatch.

All 2 comments

Hi,

Error says AuthenticationEventListener.php but service definition says AuthenticationSuccessListener, classname-filename mismatch.

my mistake.. OMG!.. i was obfuscated xD

Thanks @chalasr

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tsdevelopment picture tsdevelopment  路  4Comments

Zempheroth picture Zempheroth  路  4Comments

ghost picture ghost  路  5Comments

Walkoss picture Walkoss  路  5Comments

garak picture garak  路  5Comments