
io.sphere.internal.oauth.AccessToken Maven / Gradle / Ivy
package io.sphere.internal.oauth;
import com.google.common.base.Function;
import com.google.common.base.Optional;
/** Helper class for {@link SphereClientCredentials}. */
public class AccessToken {
private String accessToken;
private Optional originalExpiresInSeconds;
/** Time the tokens stored inside this instance were last refreshed, in System.currentTimeMillis(). */
private 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().transform(new Function() {
public Long apply(Long originalExpiresInSec) {
long expiresAtMs = updatedTimestamp + 1000 * originalExpiresInSec;
long remainingMs = expiresAtMs - System.currentTimeMillis();
return remainingMs;
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy