do not refresh token if refresh token expired
This commit is contained in:
parent
6d13086a53
commit
0cd0c65a08
@ -56,8 +56,16 @@ public class RefreshTokenExpCheckService {
|
||||
JsonNode jsonValue = settings.getJsonValue();
|
||||
if (OFFICE_365.name().equals(jsonValue.get("providerId").asText()) && jsonValue.has("refreshToken")
|
||||
&& jsonValue.has("refreshTokenExpires")) {
|
||||
try {
|
||||
long expiresIn = jsonValue.get("refreshTokenExpires").longValue();
|
||||
if ((expiresIn - System.currentTimeMillis()) < 604800000L) { //less than 7 days
|
||||
long tokenLifeDuration = expiresIn - System.currentTimeMillis();
|
||||
if (tokenLifeDuration < 0) {
|
||||
((ObjectNode) jsonValue).put("tokenGenerated", false);
|
||||
((ObjectNode) jsonValue).remove("refreshToken");
|
||||
((ObjectNode) jsonValue).remove("refreshTokenExpires");
|
||||
|
||||
adminSettingsService.saveAdminSettings(TenantId.SYS_TENANT_ID, settings);
|
||||
} else if (tokenLifeDuration < 604800000L) { //less than 7 days
|
||||
log.info("Trying to refresh refresh token.");
|
||||
|
||||
String clientId = jsonValue.get("clientId").asText();
|
||||
@ -73,6 +81,9 @@ public class RefreshTokenExpCheckService {
|
||||
((ObjectNode) jsonValue).put("refreshTokenExpires", Instant.now().plus(Duration.ofDays(AZURE_DEFAULT_REFRESH_TOKEN_LIFETIME_IN_DAYS)).toEpochMilli());
|
||||
adminSettingsService.saveAdminSettings(TenantId.SYS_TENANT_ID, settings);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error occurred while checking token", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user