io.sphere.sdk.client.AccessToken Maven / Gradle / Ivy
The newest version!
package io.sphere.sdk.client;
import java.util.Optional;
/** Helper class for {@link io.sphere.sdk.client.SphereClientCredentials}. */
class AccessToken {
private final String accessToken;
private final Optional originalExpiresInSeconds;
/** Time the tokens stored inside this instance were last refreshed, in System.currentTimeMillis(). */
private final long updatedTimestamp;
public AccessToken(String accessToken, Optional originalExpiresInSeconds, long updatedTimestamp) {
this.accessToken = accessToken;
this.originalExpiresInSeconds = originalExpiresInSeconds;
this.updatedTimestamp = updatedTimestamp;
}
public String getAccessToken() { return accessToken; }
public Optional getOriginalExpiresInSeconds() { return originalExpiresInSeconds; }
public long getUpdatedTimestamp() { return updatedTimestamp; }
public Optional getRemaniningMs() {
return getOriginalExpiresInSeconds().map(originalExpiresInSec -> {
long expiresAtMs = updatedTimestamp + 1000 * originalExpiresInSec;
return expiresAtMs - System.currentTimeMillis();
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy