Skip to content

Commit 63a23cb

Browse files
fix: Corrected a bug where logging in with an expired token requires immediate re-login.
1 parent 75c8bc4 commit 63a23cb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/java/com/patternknife/securityhelper/oauth2/config/security/serivce/persistence/authorization/OAuth2AuthorizationServiceImpl.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,18 @@ public OAuth2Authorization findByToken(@NotEmpty String tokenValue, @NotEmpty OA
174174
oAuth2Authorization = customOauthAccessToken.getAuthentication();
175175
}
176176
} catch (Exception e) {
177+
177178
exceptionHandler.accept(e);
179+
180+
// Retry only one more time
181+
customOauthAccessToken = accessTokenSupplier.get().orElse(null);
182+
if (customOauthAccessToken != null) {
183+
oAuth2Authorization = customOauthAccessToken.getAuthentication();
184+
}
178185
}
179186
if (customOauthAccessToken != null && oAuth2Authorization != null && oAuth2Authorization.getAccessToken() != null && oAuth2Authorization.getAccessToken().isExpired()) {
180187
customOauthAccessTokenRepository.deleteByTokenId(customOauthAccessToken.getTokenId());
188+
return null;
181189
}
182190

183191
return oAuth2Authorization;
@@ -222,19 +230,26 @@ public OAuth2Authorization findByToken(@NotEmpty String tokenValue, @NotEmpty OA
222230
oAuth2Authorization = customOauthRefreshToken.getAuthentication();
223231
}
224232
} catch (Exception e) {
233+
225234
exceptionHandler.accept(e);
235+
236+
// Retry only one more time
237+
customOauthRefreshToken = refreshTokenSupplier.get().orElse(null);
238+
if (customOauthRefreshToken != null) {
239+
oAuth2Authorization = customOauthRefreshToken.getAuthentication();
240+
}
226241
}
227242

228243
if (customOauthRefreshToken != null && oAuth2Authorization != null && oAuth2Authorization.getRefreshToken() != null && oAuth2Authorization.getRefreshToken().isExpired()) {
229244
customOauthRefreshTokenRepository.deleteByTokenId(customOauthRefreshToken.getTokenId());
245+
return null;
230246
}
231247
return oAuth2Authorization;
232248
}
233249

234250

235251

236252

237-
238253
/*
239254
* 4. D for Delete
240255
* */

0 commit comments

Comments
 (0)