Skip to content

Commit 61e9f7f

Browse files
committed
Fixing bug - the refresh endpoint needs ReCodEx token properly injected.
1 parent 8dcef66 commit 61e9f7f

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

app/presenters/LoginPresenter.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,25 @@ public function checkRefresh()
127127
*/
128128
public function actionRefresh()
129129
{
130+
// We need to inject the token manually here (this class is not derived from BasePresenterWithApi)
131+
$user = $this->getCurrentUser();
132+
$prefix = $user->getRecodexToken();
133+
$suffix = $this->getAccessToken()->getPayloadOrDefault('suffix', null);
134+
135+
if (!$prefix || !$suffix) {
136+
throw new ForbiddenRequestException("Cannot refresh token - user does not have a ReCodEx token.");
137+
}
138+
139+
// Call ReCodEx API to refresh the token
140+
$this->recodexApi->setAuthToken($prefix . $suffix);
130141
$recodexResponse = $this->recodexApi->refreshToken();
131142
/** @var RecodexUser */
132143
$recodexUser = $recodexResponse['user'];
133144

134-
// Update the user entity with new info from ReCodEx.
135-
$user = $this->users->findOrThrow($recodexUser->getId());
145+
// Update the user entity with new info from ReCodEx
146+
if ($recodexUser->getId() !== $user->getId()) {
147+
throw new AuthenticationException("Token refresh failed - user ID mismatch.");
148+
}
136149
$recodexUser->updateUser($user);
137150

138151
$this->finalizeLogin($user, $recodexResponse['accessToken']);

0 commit comments

Comments
 (0)