Skip to content

Commit be3a56d

Browse files
committed
prototype integration for thephpleague/oauth2-client#866
1 parent 16d0045 commit be3a56d

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

authman.services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55

66
authman.oauth:
77
class: Drupal\authman\AuthmanInstance\AuthmanOauthFactory
8-
arguments: ['@entity_type.manager']
8+
arguments: ['@entity_type.manager', '@datetime.time']
99

1010
access_check.authman.authorization_code_receive:
1111
class: Drupal\authman\Access\AuthmanAuthorizationCodeReceive

src/AuthmanClock.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Drupal\authman;
6+
7+
use Drupal\Component\Datetime\TimeInterface;
8+
use League\OAuth2\Client\Provider\Clock;
9+
10+
/**
11+
* Allows OAuth providers to use the Drupal clock.
12+
*/
13+
class AuthmanClock extends Clock {
14+
15+
/**
16+
* Time.
17+
*
18+
* @var \Drupal\Component\Datetime\TimeInterface
19+
*/
20+
protected TimeInterface $time;
21+
22+
/**
23+
* AuthmanClock constructor.
24+
*
25+
* @param \Drupal\Component\Datetime\TimeInterface $time
26+
* Time.
27+
*/
28+
public function __construct(TimeInterface $time) {
29+
$this->time = $time;
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function now() {
36+
return new \DateTimeImmutable('@' . $this->time->getRequestTime());
37+
}
38+
39+
}

src/AuthmanInstance/AuthmanOauthFactory.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Drupal\authman\AuthmanInstance;
66

7+
use Drupal\authman\AuthmanClock;
78
use Drupal\authman\Entity\AuthmanAuthInterface;
89
use Drupal\authman\EntityHandlers\AuthmanAuthStorage;
910
use Drupal\authman\Exception\AuthmanClientCredentialsException;
@@ -12,6 +13,7 @@
1213
use Drupal\authman\Exception\AuthmanPluginException;
1314
use Drupal\authman\Plugin\KeyType\OauthKeyTypeInterface;
1415
use Drupal\authman\Token\AuthmanAccessToken;
16+
use Drupal\Component\Datetime\TimeInterface;
1517
use Drupal\Core\Entity\EntityStorageInterface;
1618
use Drupal\Core\Entity\EntityTypeManagerInterface;
1719
use Drupal\Core\Url;
@@ -31,14 +33,24 @@ class AuthmanOauthFactory implements AuthmanOauthFactoryInterface {
3133
*/
3234
protected $entityTypeManager;
3335

36+
/**
37+
* Time.
38+
*
39+
* @var \Drupal\Component\Datetime\TimeInterface
40+
*/
41+
protected TimeInterface $time;
42+
3443
/**
3544
* AuthmanOauthFactory constructor.
3645
*
3746
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
3847
* The entity type manager.
48+
* @param \Drupal\Component\Datetime\TimeInterface $time
49+
* Time.
3950
*/
40-
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
51+
public function __construct(EntityTypeManagerInterface $entityTypeManager, TimeInterface $time) {
4152
$this->entityTypeManager = $entityTypeManager;
53+
$this->time = $time;
4254
}
4355

4456
/**
@@ -50,9 +62,11 @@ public function get(string $id): AuthmanOauthInstanceInterface {
5062
throw new \InvalidArgumentException('Invalid ID');
5163
}
5264

65+
$clock = new AuthmanClock($this->time);
5366
$redirectUri = Url::fromRoute('authman.authorization_code.receive', ['authman_auth' => $authmanConfig->id()]);
5467
$providerOptions = [
5568
'redirectUri' => $redirectUri->setAbsolute()->toString(TRUE)->getGeneratedUrl(),
69+
'clock' => $clock,
5670
];
5771

5872
$clientKey = $this->keyStorage()->load($authmanConfig->getClientKeyId());

0 commit comments

Comments
 (0)