diff --git a/authman.services.yml b/authman.services.yml index 16ee245..27bb81e 100644 --- a/authman.services.yml +++ b/authman.services.yml @@ -5,7 +5,7 @@ services: authman.oauth: class: Drupal\authman\AuthmanInstance\AuthmanOauthFactory - arguments: ['@entity_type.manager'] + arguments: ['@entity_type.manager', '@datetime.time'] access_check.authman.authorization_code_receive: class: Drupal\authman\Access\AuthmanAuthorizationCodeReceive diff --git a/src/AuthmanClock.php b/src/AuthmanClock.php new file mode 100644 index 0000000..63e6ae4 --- /dev/null +++ b/src/AuthmanClock.php @@ -0,0 +1,39 @@ +time = $time; + } + + /** + * {@inheritdoc} + */ + public function now() { + return new \DateTimeImmutable('@' . $this->time->getRequestTime()); + } + +} diff --git a/src/AuthmanInstance/AuthmanOauthFactory.php b/src/AuthmanInstance/AuthmanOauthFactory.php index 3baba11..fea4062 100644 --- a/src/AuthmanInstance/AuthmanOauthFactory.php +++ b/src/AuthmanInstance/AuthmanOauthFactory.php @@ -4,6 +4,7 @@ namespace Drupal\authman\AuthmanInstance; +use Drupal\authman\AuthmanClock; use Drupal\authman\Entity\AuthmanAuthInterface; use Drupal\authman\EntityHandlers\AuthmanAuthStorage; use Drupal\authman\Exception\AuthmanClientCredentialsException; @@ -12,6 +13,7 @@ use Drupal\authman\Exception\AuthmanPluginException; use Drupal\authman\Plugin\KeyType\OauthKeyTypeInterface; use Drupal\authman\Token\AuthmanAccessToken; +use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Url; @@ -31,14 +33,24 @@ class AuthmanOauthFactory implements AuthmanOauthFactoryInterface { */ protected $entityTypeManager; + /** + * Time. + * + * @var \Drupal\Component\Datetime\TimeInterface + */ + protected TimeInterface $time; + /** * AuthmanOauthFactory constructor. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager * The entity type manager. + * @param \Drupal\Component\Datetime\TimeInterface $time + * Time. */ - public function __construct(EntityTypeManagerInterface $entityTypeManager) { + public function __construct(EntityTypeManagerInterface $entityTypeManager, TimeInterface $time) { $this->entityTypeManager = $entityTypeManager; + $this->time = $time; } /** @@ -50,9 +62,11 @@ public function get(string $id): AuthmanOauthInstanceInterface { throw new \InvalidArgumentException('Invalid ID'); } + $clock = new AuthmanClock($this->time); $redirectUri = Url::fromRoute('authman.authorization_code.receive', ['authman_auth' => $authmanConfig->id()]); $providerOptions = [ 'redirectUri' => $redirectUri->setAbsolute()->toString(TRUE)->getGeneratedUrl(), + 'clock' => $clock, ]; $clientKey = $this->keyStorage()->load($authmanConfig->getClientKeyId());