File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ' ]);
You can’t perform that action at this time.
0 commit comments