Skip to content

Commit

Permalink
prototype integration for thephpleague/oauth2-client#866
Browse files Browse the repository at this point in the history
  • Loading branch information
dpi committed Nov 8, 2020
1 parent 50ee362 commit 7cc9d89
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion authman.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions src/AuthmanClock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types = 1);

namespace Drupal\authman;

use Drupal\Component\Datetime\TimeInterface;
use League\OAuth2\Client\Provider\Clock;

/**
* Allows OAuth providers to use the Drupal clock.
*/
class AuthmanClock extends Clock {

/**
* Time.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected TimeInterface $time;

/**
* AuthmanClock constructor.
*
* @param \Drupal\Component\Datetime\TimeInterface $time
* Time.
*/
public function __construct(TimeInterface $time) {
$this->time = $time;
}

/**
* {@inheritdoc}
*/
public function now() {
return new \DateTimeImmutable('@' . $this->time->getRequestTime());
}

}
16 changes: 15 additions & 1 deletion src/AuthmanInstance/AuthmanOauthFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -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());
Expand Down

0 comments on commit 7cc9d89

Please sign in to comment.