Skip to content

Commit

Permalink
Add in the "aud" claim.
Browse files Browse the repository at this point in the history
... ensure we're dealing with our tokens.
  • Loading branch information
adam-vessey committed Jun 22, 2021
1 parent 2f06c98 commit 11057e9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Event/StompHeaderEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Event used to build headers for STOMP.
*/
class StompHeaderEvent implements StompHeaderEventInterface {
class StompHeaderEvent extends Event implements StompHeaderEventInterface {

/**
* Stashed entity, for context.
Expand Down
2 changes: 2 additions & 0 deletions src/EventGenerator/EmitEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\islandora\Event\StompHeaderEvent;
use Drupal\islandora\Event\StompHeaderEventException;
use Stomp\Exception\StompException;
use Stomp\StatefulStomp;
use Stomp\Transport\Message;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Configurable action base for actions that publish messages to queues.
Expand Down
7 changes: 7 additions & 0 deletions src/EventSubscriber/JwtEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
class JwtEventSubscriber implements EventSubscriberInterface {

const AUDIENCE = 'islandora';

/**
* User storage to load users.
*
Expand Down Expand Up @@ -100,6 +102,7 @@ public function setIslandoraClaims(JwtAuthGenerateEvent $event) {
$event->addClaim('sub', $this->currentUser->getAccountName());
$event->addClaim('roles', $this->currentUser->getRoles(FALSE));

$event->addClaim('aud', [static::AUDIENCE]);
}

/**
Expand All @@ -111,6 +114,10 @@ public function setIslandoraClaims(JwtAuthGenerateEvent $event) {
public function validate(JwtAuthValidateEvent $event) {
$token = $event->getToken();

if (!in_array(static::AUDIENCE, $token->getClaim('aud'), TRUE)) {
$event->invalidate('Missing audience entry.');
}

$uid = $token->getClaim('webid');
$name = $token->getClaim('sub');
$roles = $token->getClaim('roles');
Expand Down

0 comments on commit 11057e9

Please sign in to comment.