custom/plugins/PickwareWms/vendor/pickware/mobile-app-auth-bundle/src/OAuth/ApiPinAuthenticationSubscriber.php line 66

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (c) Pickware GmbH. All rights reserved.
  4.  * This file is part of software that is released under a proprietary license.
  5.  * You must not copy, modify, distribute, make publicly available, or execute
  6.  * its contents or parts thereof without express permission by the copyright
  7.  * holder, unless otherwise permitted by law.
  8.  */
  9. declare(strict_types=1);
  10. namespace Pickware\MobileAppAuthBundle\OAuth;
  11. use DateInterval;
  12. use League\OAuth2\Server\AuthorizationServer;
  13. use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
  14. use League\OAuth2\Server\Repositories\UserRepositoryInterface;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Component\HttpKernel\Event\RequestEvent;
  17. use Symfony\Component\HttpKernel\KernelEvents;
  18. class ApiPinAuthenticationSubscriber implements EventSubscriberInterface
  19. {
  20.     /**
  21.      * @var AuthorizationServer
  22.      */
  23.     private $authorizationServer;
  24.     /**
  25.      * @var UserRepositoryInterface
  26.      */
  27.     private $userRepository;
  28.     /**
  29.      * @var RefreshTokenRepositoryInterface
  30.      */
  31.     private $refreshTokenRepository;
  32.     public function __construct(
  33.         AuthorizationServer $authorizationServer,
  34.         UserRepositoryInterface $userRepository,
  35.         RefreshTokenRepositoryInterface $refreshTokenRepository
  36.     ) {
  37.         $this->authorizationServer $authorizationServer;
  38.         $this->userRepository $userRepository;
  39.         $this->refreshTokenRepository $refreshTokenRepository;
  40.     }
  41.     public static function getSubscribedEvents(): array
  42.     {
  43.         // Shopware's OAuth subscriber subscribes itself at position 128, use the same here. This ensures that other
  44.         // subscribers which expect the authorization server to be configured already can use an appropriate priority
  45.         // number and do not need to distinguish between shopware's priority and ours.
  46.         return [
  47.             KernelEvents::REQUEST => [
  48.                 [
  49.                     'setupPinBasedOAuth',
  50.                     128,
  51.                 ],
  52.             ],
  53.         ];
  54.     }
  55.     public function setupPinBasedOAuth(RequestEvent $event): void
  56.     {
  57.         if (!$event->isMasterRequest()) {
  58.             return;
  59.         }
  60.         $pinGrant = new PinGrant($this->userRepository$this->refreshTokenRepository);
  61.         $tenMinuteInterval = new DateInterval('PT10M');
  62.         $this->authorizationServer->enableGrantType($pinGrant$tenMinuteInterval);
  63.     }
  64. }