public class AuthState extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
AuthState.AuthStateAction
Interface for actions executed in the context of fresh (non-expired) tokens.
|
Modifier and Type | Field and Description |
---|---|
static int |
EXPIRY_TIME_TOLERANCE_MS
Tokens which have less time than this value left before expiry will be considered to be
expired for the purposes of calls to
performActionWithFreshTokens . |
Constructor and Description |
---|
AuthState()
Creates an empty, unauthenticated
AuthState . |
AuthState(AuthorizationResponse authResponse,
Exception authError)
Creates an
AuthState based on an authorization exchange. |
AuthState(AuthorizationResponse authResponse,
TokenResponse tokenResponse)
Creates an
AuthState based on an authorization exchange and subsequent token
exchange. |
Modifier and Type | Method and Description |
---|---|
TokenRequest |
createTokenRefreshRequest()
Creates a token request for new tokens using the current refresh token.
|
TokenRequest |
createTokenRefreshRequest(Map<String,String> additionalParameters)
Creates a token request for new tokens using the current refresh token, adding the
specified additional parameters.
|
static AuthState |
fromJson(JSONObject json)
Restores authorization state from JSON produced by
toJson() . |
static AuthState |
fromJson(String jsonStr)
Restored authorization state from a JSON string produced by
toJsonString() . |
String |
getAccessToken()
The current access token, if available.
|
Long |
getAccessTokenExpirationTime()
The expiration time of the current access token (if available), as milliseconds from the
UNIX epoch (consistent with
System.currentTimeMillis() ). |
AuthorizationServiceConfiguration |
getAuthorizationServiceConfiguration()
The configuration of the authorization service associated with this authorization state.
|
String |
getIdToken()
The current ID token, if available.
|
AuthorizationResponse |
getLastAuthorizationResponse()
The most recent authorization response used to update the authorization state.
|
TokenResponse |
getLastTokenResponse()
The most recent token response used to update this authorization state.
|
boolean |
getNeedsTokenRefresh()
Determines whether the access token is considered to have expired.
|
String |
getRefreshToken()
The most recent refresh token received from the server, if available.
|
String |
getScope()
The scope of the current authorization grant.
|
Set<String> |
getScopeSet()
A set representation of
getScope() , for convenience. |
boolean |
isAuthorized()
Determines whether the current state represents a successful authorization,
from which at least either an access token or an ID token have been retrieved.
|
void |
performActionWithFreshTokens(AuthorizationService service,
AuthState.AuthStateAction action)
Ensures that a non-expired access token is available before invoking the provided action.
|
void |
performActionWithFreshTokens(AuthorizationService service,
Map<String,String> refreshTokenAdditionalParams,
AuthState.AuthStateAction action)
Ensures that a non-expired access token is available before invoking the provided action.
|
void |
setNeedsTokenRefresh(boolean needsTokenRefresh)
Sets whether to force an access token refresh, irrespective of the expiration time.
|
JSONObject |
toJson()
Converts the authorization state to a JSON object for storage or transmission.
|
String |
toJsonString()
Converts the authorization state to a JSON string for storage or transmission.
|
void |
update(AuthorizationResponse authResponse,
Exception authError)
Updates the authorization state based on a new authorization response.
|
void |
update(TokenResponse tokenResponse,
Exception authError)
Updates the authorization state based on a new token response.
|
public static final int EXPIRY_TIME_TOLERANCE_MS
performActionWithFreshTokens
.public AuthState()
AuthState
.public AuthState(@Nullable AuthorizationResponse authResponse, @Nullable Exception authError)
AuthState
based on an authorization exchange.public AuthState(@NonNull AuthorizationResponse authResponse, @NonNull TokenResponse tokenResponse)
AuthState
based on an authorization exchange and subsequent token
exchange.@Nullable public String getRefreshToken()
performActionWithFreshTokens
to ensure that fresh tokens are available.@Nullable public String getScope()
@Nullable public Set<String> getScopeSet()
getScope()
, for convenience.@Nullable public AuthorizationResponse getLastAuthorizationResponse()
access token
,
access token expiration
,
ID token
and scope
regardless of the flow used to retrieve them.@Nullable public TokenResponse getLastTokenResponse()
access token
,
access token expiration
,
ID token
and scope
regardless of the flow used to retrieve them.@Nullable public AuthorizationServiceConfiguration getAuthorizationServiceConfiguration()
@Nullable public String getAccessToken()
performActionWithFreshTokens
to ensure that fresh tokens are available.@Nullable public Long getAccessTokenExpirationTime()
System.currentTimeMillis()
).public boolean isAuthorized()
public boolean getNeedsTokenRefresh()
public void setNeedsTokenRefresh(boolean needsTokenRefresh)
public void update(@Nullable AuthorizationResponse authResponse, @Nullable Exception authError)
public void update(@Nullable TokenResponse tokenResponse, @Nullable Exception authError)
public void performActionWithFreshTokens(@NonNull AuthorizationService service, @NonNull AuthState.AuthStateAction action)
public void performActionWithFreshTokens(@NonNull AuthorizationService service, @NonNull Map<String,String> refreshTokenAdditionalParams, @NonNull AuthState.AuthStateAction action)
public TokenRequest createTokenRefreshRequest()
public TokenRequest createTokenRefreshRequest(@NonNull Map<String,String> additionalParameters)
public JSONObject toJson()
public String toJsonString()
public static AuthState fromJson(@NonNull JSONObject json) throws JSONException
toJson()
.JSONException
- if the JSON is malformed or missing required fields.public static AuthState fromJson(@NonNull String jsonStr) throws JSONException
toJsonString()
.JSONException
- if the JSON is malformed or missing required fields.