Reputation: 92
Following the link https://github.com/thephpleague/oauth2-server-bundle/blob/master/docs/listening-to-league-events.md#listening-to-league-oauth-server-events I registered a listener for the OAuth2Events::TOKEN_REQUEST_RESOLVE event
<?php
// https://github.com/thephpleague/oauth2-server-bundle/blob/master/docs/listening-to-league-events.md#listening-to-league-oauth-server-events
namespace App\EventListener;
use League\Bundle\OAuth2ServerBundle\OAuth2Events;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
final class RequestTokenResolveListener
{
#[AsEventListener(event: OAuth2Events::TOKEN_REQUEST_RESOLVE)]
public function onLeagueOauth2ServerEventTokenRequestResolve($event): void
{
$event->resolveAuthorization(true);
}
}
The goal is to direct the user to the consent screen if necessary or validate and approve access
The problem is that the "AsEventListener" attribute does not work at the time the event is fired. However, it is triggered at the end of the request.
It was created using the "make:listener" command.
Logging the event in the service.yml works.
services:
App\EventListener\RequestTokenResolveListener:
tags:
- { name: kernel.event_listener, event: league.oauth2_server.event.authorization_request_resolve, method: onLeagueOauth2ServerEventTokenRequestResolve }
I'm using Symfony LTS (6.4). Did I forget something?
Upvotes: 0
Views: 56
Reputation: 21
You're intervening deep into the event stack of the framework. kernel level event's have a higher priority and are getting executed first.
Try:
#[AsEventListener(event: OAuth2Events::TOKEN_REQUEST_RESOLVE, priority: 256)]
See the following: https://symfony.com/doc/current/event_dispatcher.html#creating-an-event-listener
Upvotes: 2