mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Adapt to AccessTokenResponse API change (#13278)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
29fb142e6a
commit
19659b6e05
@ -13,7 +13,7 @@
|
||||
package org.openhab.binding.automower.internal.bridge;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -55,7 +55,7 @@ public class AutomowerBridge {
|
||||
private AccessTokenResponse authenticate() throws AutomowerCommunicationException {
|
||||
try {
|
||||
AccessTokenResponse result = authService.getAccessTokenResponse();
|
||||
if (result == null || result.isExpired(LocalDateTime.now(), 120)) {
|
||||
if (result == null || result.isExpired(Instant.now(), 120)) {
|
||||
result = authService.getAccessTokenByClientCredentials(null);
|
||||
}
|
||||
return result;
|
||||
|
@ -19,7 +19,7 @@ import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
@ -151,7 +151,7 @@ public class EcobeeApi implements AccessTokenRefreshListener {
|
||||
AccessTokenResponse localAccessTokenResponse = oAuthClientService.getAccessTokenResponse();
|
||||
if (localAccessTokenResponse != null) {
|
||||
logger.trace("API: Got AccessTokenResponse from OAuth service: {}", localAccessTokenResponse);
|
||||
if (localAccessTokenResponse.isExpired(LocalDateTime.now(), TOKEN_EXPIRES_IN_BUFFER_SECONDS)) {
|
||||
if (localAccessTokenResponse.isExpired(Instant.now(), TOKEN_EXPIRES_IN_BUFFER_SECONDS)) {
|
||||
logger.debug("API: Token is expiring soon. Refresh it now");
|
||||
localAccessTokenResponse = oAuthClientService.refreshToken();
|
||||
}
|
||||
|
@ -17,7 +17,9 @@ import static io.github.bucket4j.Refill.intervally;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -96,8 +98,7 @@ public class HttpHelper {
|
||||
try {
|
||||
AccessTokenResponse accessTokenResponse = oAuthClientService.getAccessTokenResponse();
|
||||
// refresh the token if it's about to expire
|
||||
if (accessTokenResponse != null
|
||||
&& accessTokenResponse.isExpired(LocalDateTime.now(), OAUTH_EXPIRE_BUFFER)) {
|
||||
if (accessTokenResponse != null && accessTokenResponse.isExpired(Instant.now(), OAUTH_EXPIRE_BUFFER)) {
|
||||
LoggerFactory.getLogger(HttpHelper.class).debug("Requesting a refresh of the access token.");
|
||||
accessTokenResponse = oAuthClientService.refreshToken();
|
||||
}
|
||||
@ -106,11 +107,14 @@ public class HttpHelper {
|
||||
String lastToken = lastAccessToken;
|
||||
if (lastToken == null) {
|
||||
LoggerFactory.getLogger(HttpHelper.class).debug("The used access token was created at {}",
|
||||
accessTokenResponse.getCreatedOn().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||
LocalDateTime.ofInstant(accessTokenResponse.getCreatedOn(), ZoneId.systemDefault())
|
||||
.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||
} else if (!lastToken.equals(accessTokenResponse.getAccessToken())) {
|
||||
LoggerFactory.getLogger(HttpHelper.class).debug(
|
||||
"The access token changed. New one created at {}",
|
||||
accessTokenResponse.getCreatedOn().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||
LoggerFactory.getLogger(HttpHelper.class)
|
||||
.debug("The access token changed. New one created at {}",
|
||||
LocalDateTime
|
||||
.ofInstant(accessTokenResponse.getCreatedOn(), ZoneId.systemDefault())
|
||||
.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||
}
|
||||
lastAccessToken = accessTokenResponse.getAccessToken();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user