-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #65 Add ability to listen to League events via Symfony listen…
…ers/subscribers (X-Coder264) This PR was merged into the 0.1-dev branch. Discussion ---------- Add ability to listen to League events via Symfony listeners/subscribers This is a very simple approach to emit League OAuth server events via the Symfony event dispatcher so that users can create their own listeners in their Symfony applications. Closes #35 Commits ------- cf5b9fc Enable users to listen on League events via Symfony listeners
- Loading branch information
Showing
6 changed files
with
220 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# 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 | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EventListener; | ||
|
||
use League\OAuth2\Server\RequestAccessTokenEvent; | ||
|
||
final class FooListener | ||
{ | ||
public function onAccessTokenIssuedEvent(RequestAccessTokenEvent $event): void | ||
{ | ||
// do something | ||
} | ||
} | ||
``` | ||
|
||
1. Register the event listener: | ||
|
||
```yaml | ||
services: | ||
App\EventListener\FooListener: | ||
tags: | ||
- { name: kernel.event_listener, event: access_token.issued, method: onAccessTokenIssuedEvent } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\Bundle\OAuth2ServerBundle\Service; | ||
|
||
use League\Event\EventInterface; | ||
use League\Event\ListenerAcceptorInterface; | ||
use League\Event\ListenerProviderInterface; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; | ||
|
||
final class SymfonyLeagueEventListenerProvider implements ListenerProviderInterface | ||
{ | ||
/** | ||
* @var EventDispatcherInterface | ||
*/ | ||
private $eventDispatcher; | ||
|
||
public function __construct(EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
|
||
public function provideListeners(ListenerAcceptorInterface $listenerAcceptor) | ||
{ | ||
$listener = \Closure::fromCallable([$this, 'dispatchLeagueEventWithSymfonyEventDispatcher']); | ||
|
||
$listenerAcceptor->addListener('*', $listener); | ||
|
||
return $this; | ||
} | ||
|
||
private function dispatchLeagueEventWithSymfonyEventDispatcher(EventInterface $event): void | ||
{ | ||
$this->eventDispatcher->dispatch($event, $event->getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters