Skip to content

Commit a75b6a9

Browse files
Merge pull request #869 from City-of-Helsinki/ASU-1793-fix-rest-api
ASU-1793: Fix drupal11 compatibility issues
2 parents 2c6847d + ebce3a2 commit a75b6a9

4 files changed

Lines changed: 98 additions & 4 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@
176176
"[D11] Fix simple_oauth normalizer signatures for Symfony 7": "patches/simple_oauth-symfony7-normalizer-signatures.patch",
177177
"[D11] Replace watchdog_exception() usage": "patches/simple_oauth-drupal11-watchdog-exception.patch",
178178
"[Symfony 7] Fix BasicAuthSwap handle signature": "patches/simple_oauth-symfony7-basicauthswap-handle-signature.patch",
179-
"[PHP 7.4+] Initialize ResourceServer subject property": "patches/simple_oauth-resource-server-subject-init.patch"
179+
"[PHP 7.4+] Initialize ResourceServer subject property": "patches/simple_oauth-resource-server-subject-init.patch",
180+
"[D11.1] Implement EntityInterface::getBundleEntity/getOriginal/setOriginal on TokenAuthUser": "patches/simple_oauth-d11-entity-interface-methods.patch"
180181
},
181182
"drupal/config_terms": {
182183
"Drupal 11 compatibility fixes": "https://www.drupal.org/files/issues/2024-06-02/config_terms.1.x-dev.rector.patch"

patches.lock.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"_hash": "ccee31539065b31a7ffddc3061bfcc89bf35f33588afaee9162d7b5be83bc859",
2+
"_hash": "bba7ab1d8144f65b9b08f67a72e2b8fa012c597b789a621626f10cd640000d41",
33
"patches": {
44
"drupal/helfi_platform_config": [
55
{
@@ -48,7 +48,7 @@
4848
"package": "drupal/simple_oauth",
4949
"description": "[D11] Replace watchdog_exception() usage",
5050
"url": "patches/simple_oauth-drupal11-watchdog-exception.patch",
51-
"sha256": "5ff871af833d7d468b7542db43202b8a0530a84fa8e754e114253964f60c0aa3",
51+
"sha256": "c7898af92e634b042d40c8b2005bfcccf7edfebdcffd4002a8a9c5783b7027b9",
5252
"depth": 1,
5353
"extra": {
5454
"provenance": "root"
@@ -73,6 +73,16 @@
7373
"extra": {
7474
"provenance": "root"
7575
}
76+
},
77+
{
78+
"package": "drupal/simple_oauth",
79+
"description": "[D11.1] Implement EntityInterface::getBundleEntity/getOriginal/setOriginal on TokenAuthUser",
80+
"url": "patches/simple_oauth-d11-entity-interface-methods.patch",
81+
"sha256": "5044b209e54c399a35d447677f414baf0c896dfc2dab83f4d0ee8039dc89867c",
82+
"depth": 1,
83+
"extra": {
84+
"provenance": "root"
85+
}
7686
}
7787
],
7888
"drupal/config_terms": [
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
diff --git a/src/Authentication/TokenAuthUser.php b/src/Authentication/TokenAuthUser.php
2+
--- a/src/Authentication/TokenAuthUser.php
3+
+++ b/src/Authentication/TokenAuthUser.php
4+
@@ -3,6 +3,7 @@
5+
namespace Drupal\simple_oauth\Authentication;
6+
7+
use Drupal\consumers\Entity\ConsumerInterface;
8+
+use Drupal\Core\Entity\EntityInterface;
9+
use Drupal\Core\Entity\EntityStorageInterface;
10+
use Drupal\Core\Entity\EntityTypeInterface;
11+
use Drupal\Core\Session\AccountInterface;
12+
@@ -74,6 +75,35 @@ class TokenAuthUser implements TokenAuthUserInterface {
13+
*/
14+
public function getConsumer(): ConsumerInterface {
15+
return $this->consumer;
16+
+ }
17+
+
18+
+ /**
19+
+ * {@inheritdoc}
20+
+ */
21+
+ public function getBundleEntity(): ?EntityInterface {
22+
+ // Only supported when the decorated subject is a content entity.
23+
+ return method_exists($this->subject, 'getBundleEntity')
24+
+ ? $this->subject->getBundleEntity()
25+
+ : NULL;
26+
+ }
27+
+
28+
+ /**
29+
+ * {@inheritdoc}
30+
+ */
31+
+ public function getOriginal(): ?static {
32+
+ return method_exists($this->subject, 'getOriginal')
33+
+ ? $this->subject->getOriginal()
34+
+ : NULL;
35+
+ }
36+
+
37+
+ /**
38+
+ * {@inheritdoc}
39+
+ */
40+
+ public function setOriginal(?EntityInterface $original): static {
41+
+ if (method_exists($this->subject, 'setOriginal')) {
42+
+ $this->subject->setOriginal($original);
43+
+ }
44+
+ return $this;
45+
}
46+
47+
/**

patches/simple_oauth-drupal11-watchdog-exception.patch

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
diff --git a/src/Controller/Oauth2Token.php b/src/Controller/Oauth2Token.php
2-
index a00f01b..9811498 100644
32
--- a/src/Controller/Oauth2Token.php
43
+++ b/src/Controller/Oauth2Token.php
54
@@ -69,7 +69,7 @@ class Oauth2Token extends ControllerBase {
@@ -11,3 +10,40 @@ index a00f01b..9811498 100644
1110
$response = $exception->generateHttpResponse(new Response());
1211
}
1312
return $response;
13+
diff --git a/src/Authentication/Provider/SimpleOauthAuthenticationProvider.php b/src/Authentication/Provider/SimpleOauthAuthenticationProvider.php
14+
--- a/src/Authentication/Provider/SimpleOauthAuthenticationProvider.php
15+
+++ b/src/Authentication/Provider/SimpleOauthAuthenticationProvider.php
16+
@@ -4,6 +4,7 @@ namespace Drupal\simple_oauth\Authentication\Provider;
17+
18+
use Drupal\Core\Authentication\AuthenticationProviderInterface;
19+
use Drupal\Core\Entity\EntityTypeManagerInterface;
20+
+use Drupal\Core\Logger\LoggerChannelTrait;
21+
use Drupal\Core\StringTranslation\StringTranslationTrait;
22+
use Drupal\simple_oauth\Authentication\TokenAuthUser;
23+
use Drupal\simple_oauth\PageCache\SimpleOauthRequestPolicyInterface;
24+
@@ -18,6 +19,7 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
25+
class SimpleOauthAuthenticationProvider implements AuthenticationProviderInterface {
26+
27+
use StringTranslationTrait;
28+
+ use LoggerChannelTrait;
29+
30+
/**
31+
* @var \Drupal\simple_oauth\Server\ResourceServerInterface
32+
@@ -79,7 +81,7 @@ class SimpleOauthAuthenticationProvider implements AuthenticationProviderInterfa
33+
}
34+
catch (OAuthServerException $exception) {
35+
// Procedural code here is hard to avoid.
36+
- watchdog_exception('simple_oauth', $exception);
37+
+ $this->getLogger('simple_oauth')->error($exception->getMessage(), ['exception' => $exception]);
38+
39+
throw new HttpException(
40+
$exception->getHttpStatusCode(),
41+
@@ -106,7 +108,7 @@ class SimpleOauthAuthenticationProvider implements AuthenticationProviderInterfa
42+
['%name' => $account->getAccountName()]
43+
)
44+
);
45+
- watchdog_exception('simple_oauth', $exception);
46+
+ $this->getLogger('simple_oauth')->error($exception->getMessage(), ['exception' => $exception]);
47+
throw new HttpException(
48+
$exception->getHttpStatusCode(),
49+
$exception->getHint(),

0 commit comments

Comments
 (0)