Skip to content

Latest commit

 

History

History
37 lines (26 loc) · 981 Bytes

listening-to-league-events.md

File metadata and controls

37 lines (26 loc) · 981 Bytes

Listening to League OAuth Server events

During the lifecycle of a request passing through the authorization server a number of events may be dispatched. A list of those event names can be found in the constants of the \League\OAuth2\Server\RequestEvent class.

In order to listen to those events you need to create a standard Symfony event listener or subscriber for them.

Example:

  1. Create the event listener.

    <?php
    
    declare(strict_types=1);
    
    namespace App\EventListener;
    
    use League\OAuth2\Server\RequestAccessTokenEvent;
    
    final class FooListener
    {
        public function onAccessTokenIssuedEvent(RequestAccessTokenEvent $event): void
        {
            // do something
        }
    }
  2. Register the event listener:

    services:
        App\EventListener\FooListener:
            tags:
                - { name: kernel.event_listener, event: access_token.issued, method: onAccessTokenIssuedEvent }