Class OAuthToken

java.lang.Object
com.eqixiac.equinix.core.model.OAuthToken

public class OAuthToken extends Object
An OAuth2 access token as returned by the Equinix token endpoint, plus the local session-start instant used to judge expiry.

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 Details

    • OAuthToken

      public OAuthToken()
      For Jackson: field-bound deserialization of the token endpoint response.
    • OAuthToken

      public 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 via EquinixClient#setOAuthToken.
      Parameters:
      sessionToken - the bearer access token
      tokenType - the token type (e.g. "bearer")
      tokenTimeout - the validity window in seconds, as returned by the token endpoint
      sessionStart - the instant the validity window started
  • Method Details

    • fromBearerToken

      public static OAuthToken fromBearerToken(BearerToken token)
      Wraps a token from a BearerTokenProvider.
      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; see validSession(Instant).
      Returns:
      true if the token can still sign requests
    • validSession

      public boolean validSession(Instant now)
      Whether this token is still usable at now: 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:
      true if the token can still sign requests