Class OAuthToken
Concurrency contract
An OAuthToken instance is immutable once populated by deserialization -
there are no setters, so the documented contract is enforced rather than merely
promised. The SDK publishes a freshly authenticated instance to multiple threads
(see EquinixClient#getOAuthToken() / setOAuthToken); the fields that
participate in the validity check (sessionStart, sessionToken and
tokenTimeout) are declared volatile so a thread reading the token
always observes the fully-written values even when the instance is handed over
without further synchronization.
Expiry clock
Validity is measured on the machine-independent Instant timeline, not local
wall-clock time, so DST transitions and system-clock adjustments cannot make an expired
token appear valid. A small safety margin (30s) treats the token as expired slightly
early so in-flight requests do not race the server-side expiry.
- Author:
- ianjones
-
Constructor Summary
ConstructorsConstructorDescriptionFor Jackson: field-bound deserialization of the token endpoint response.OAuthToken(String sessionToken, String tokenType, String tokenTimeout, Instant sessionStart) Constructs a fully populated token - intended for tests and for advanced callers that inject a token obtained out-of-band viaEquinixClient#setOAuthToken. -
Method Summary
Modifier and TypeMethodDescriptionstatic OAuthTokenfromBearerToken(BearerToken token) Wraps a token from aBearerTokenProvider.booleanWhether this token is still usable now; seevalidSession(Instant).booleanvalidSession(Instant now) Whether this token is still usable atnow: it has a bearer value and its validity window (less a 30 second safety margin) has not elapsed.
-
Constructor Details
-
OAuthToken
public OAuthToken()For Jackson: field-bound deserialization of the token endpoint response. -
OAuthToken
Constructs a fully populated token - intended for tests and for advanced callers that inject a token obtained out-of-band viaEquinixClient#setOAuthToken.- Parameters:
sessionToken- the bearer access tokentokenType- the token type (e.g."bearer")tokenTimeout- the validity window in seconds, as returned by the token endpointsessionStart- the instant the validity window started
-
-
Method Details
-
fromBearerToken
Wraps a token from aBearerTokenProvider.- Parameters:
token- the supplied token- Returns:
- a token whose validity is the supplied expiry (or unbounded when unknown)
-
validSession
public boolean validSession()Whether this token is still usable now; seevalidSession(Instant).- Returns:
trueif the token can still sign requests
-
validSession
Whether this token is still usable atnow: it has a bearer value and its validity window (less a 30 second safety margin) has not elapsed. A provider-supplied token without a known expiry is valid until the service rejects it.- Parameters:
now- the instant to judge validity at (the SDK passes its clock's reading)- Returns:
trueif the token can still sign requests
-