Package com.dropbox.core.oauth
Class DbxCredential
- java.lang.Object
-
- com.dropbox.core.oauth.DbxCredential
-
public class DbxCredential extends java.lang.Object
Use this class to store the OAuth2 result. It wraps the access token, refresh token, token expiration time as well app key and app secret, which is used for refreshing call. The object can be serialized to or deserialized from persistent storage.DbxClientV2
andDbxTeamClientV2
use this class to construct clients supporting short-live token and refresh token.
-
-
Field Summary
Fields Modifier and Type Field Description static long
EXPIRE_MARGIN
The margin that we think access token is "about to" expire.static JsonReader<DbxCredential>
Reader
static JsonWriter<DbxCredential>
Writer
-
Constructor Summary
Constructors Constructor Description DbxCredential(java.lang.String accessToken)
Create a DbxCredential object that doesn't support refreshing.DbxCredential(java.lang.String accessToken, java.lang.Long expiresAt, java.lang.String refreshToken, java.lang.String appKey)
Create a DbxCredential object if your app uses PKCE.DbxCredential(java.lang.String accessToken, java.lang.Long expiresAt, java.lang.String refreshToken, java.lang.String appKey, java.lang.String appSecret)
Create a DbxCredential object supporting refreshing short live tokens.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
aboutToExpire()
java.lang.String
getAccessToken()
Returns the OAuth access token to use for authorization with Dropbox servers.java.lang.String
getAppKey()
java.lang.String
getAppSecret()
java.lang.Long
getExpiresAt()
Return the millisecond when accessToken is going to expire.java.lang.String
getRefreshToken()
Return the refresh token which can be used to obtain new access token.DbxRefreshResult
refresh(DbxRequestConfig requestConfig)
Refresh the short live access token.DbxRefreshResult
refresh(DbxRequestConfig requestConfig, DbxHost host, java.util.Collection<java.lang.String> scope)
This should be used only in internal testing.DbxRefreshResult
refresh(DbxRequestConfig requestConfig, java.util.Collection<java.lang.String> scope)
Refresh the short live access token.java.lang.String
toString()
-
-
-
Field Detail
-
EXPIRE_MARGIN
public static final long EXPIRE_MARGIN
The margin that we think access token is "about to" expire. Within this margin, dropbox client would think the token is already expired and automatically refresh if possible.- See Also:
- Constant Field Values
-
Reader
public static final JsonReader<DbxCredential> Reader
-
Writer
public static final JsonWriter<DbxCredential> Writer
-
-
Constructor Detail
-
DbxCredential
public DbxCredential(java.lang.String accessToken)
Create a DbxCredential object that doesn't support refreshing.- Parameters:
accessToken
- Short live token or legacty long live token.
-
DbxCredential
public DbxCredential(java.lang.String accessToken, java.lang.Long expiresAt, java.lang.String refreshToken, java.lang.String appKey)
Create a DbxCredential object if your app uses PKCE. PKCE flow doesn't requrie app secret.- Parameters:
accessToken
- Short-lived access token from OAuth flow.expiresAt
- Expiration time in millisecond from OAuth flow.refreshToken
- Refresh token from OAuth flow.appKey
- You app's client id.- See Also:
to learn what is PKCE.
-
DbxCredential
public DbxCredential(java.lang.String accessToken, java.lang.Long expiresAt, java.lang.String refreshToken, java.lang.String appKey, java.lang.String appSecret)
Create a DbxCredential object supporting refreshing short live tokens.- Parameters:
accessToken
- Short-lived access token from OAuth flow.expiresAt
- Expiration time in millisecond from OAuth flow.refreshToken
- Refresh token from OAuth flowappKey
- You app's client id.appSecret
- You app's client secret.
-
-
Method Detail
-
getAccessToken
public java.lang.String getAccessToken()
Returns the OAuth access token to use for authorization with Dropbox servers.- Returns:
- OAuth access token
-
getExpiresAt
public java.lang.Long getExpiresAt()
Return the millisecond when accessToken is going to expire.- Returns:
- ExpiresAt in millisecond.
-
getAppKey
public java.lang.String getAppKey()
-
getAppSecret
public java.lang.String getAppSecret()
-
getRefreshToken
public java.lang.String getRefreshToken()
Return the refresh token which can be used to obtain new access token.- Returns:
- Refresh Token.
-
aboutToExpire
public boolean aboutToExpire()
- Returns:
- true if access token is already expired or current time is within the \300000L to expiration time.
-
refresh
public DbxRefreshResult refresh(DbxRequestConfig requestConfig, DbxHost host, java.util.Collection<java.lang.String> scope) throws DbxException
This should be used only in internal testing. Same asrefresh(DbxRequestConfig)
but just add host.- Parameters:
requestConfig
- request config used to make http request.host
- which host to call, only used in internal testing.scope
- space-delimited scope list. Must be subset of scope in current oauth2 grant.- Returns:
- DbxRefreshResult which contains app key and app secret.
- Throws:
DbxOAuthException
- If refresh failed becasue of invalid refresh parameter or refresh token is revoked.DbxException
- If refresh failed for general errors.
-
refresh
public DbxRefreshResult refresh(DbxRequestConfig requestConfig) throws DbxException
Refresh the short live access token. If succeeds, the access token and expiration time value inside this object will be overwritten to new values.- Parameters:
requestConfig
- request config used to make http request.- Returns:
- DbxRefreshResult which contains app key and app secret.
- Throws:
DbxOAuthException
- If refresh failed because of invalid refresh parameter or refresh token is invalid or revoked.DbxException
- If refresh failed for general errors.
-
refresh
public DbxRefreshResult refresh(DbxRequestConfig requestConfig, java.util.Collection<java.lang.String> scope) throws DbxException
Refresh the short live access token. If succeeds, the access token and expiration time value inside this object will be overwritten to new values.- Parameters:
requestConfig
- request config used to make http request.scope
- Must be a subset of original scopes requested with this OAuth2 grant. You can use this method to obtain a new short lived token with less access than the original one.- Returns:
- DbxRefreshResult which contains app key and app secret.
- Throws:
DbxOAuthException
- If refresh failed because of invalid refresh parameter or refresh token is invalid or revoked.DbxException
- If refresh failed for general errors.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Returns:
- The json string containing all fields.
-
-