Skip to content

Commit 9aaa274

Browse files
[5.4] Handle 401 Unauthorized error instead of throwing CRITICAL uncaught 500 server (joomla#46305)
1 parent 7e9034a commit 9aaa274

File tree

1 file changed

+11
-0
lines changed
  • plugins/api-authentication/token/src/Extension

1 file changed

+11
-0
lines changed

plugins/api-authentication/token/src/Extension/Token.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ public function onUserAuthenticate(AuthenticationEvent $event): void
168168
*/
169169
$allowedAlgo = \in_array($algo, $this->allowedAlgos);
170170

171+
// If the algorithm is not allowed, fail authentication gracefully.
172+
if (!$allowedAlgo) {
173+
return;
174+
}
175+
171176
/**
172177
* Make sure the user ID is an integer
173178
*/
@@ -190,6 +195,12 @@ public function onUserAuthenticate(AuthenticationEvent $event): void
190195
$referenceTokenData = $this->getTokenSeedForUser($userId);
191196
$referenceTokenData = empty($referenceTokenData) ? '' : $referenceTokenData;
192197
$referenceTokenData = base64_decode($referenceTokenData);
198+
199+
// If the reference token data is empty, user has no token configured.
200+
if (empty($referenceTokenData)) {
201+
return;
202+
}
203+
193204
$referenceHMAC = hash_hmac($algo, $referenceTokenData, $siteSecret);
194205

195206
// Is the token enabled?

0 commit comments

Comments
 (0)