public final class InMemoryOAuth2TokenStorage extends java.lang.Object implements OAuth2TokenStorage
This in-memory storage, as its name implies, lives as long as the application process is running. Internally, it uses a ConcurrentHashMap
to store the tokens.
If you need to persist the tokens somehow then use the saveStorageToBundle(Bundle, String)
method to save the data to a bundle and the
readStorageFromBundle(Bundle, String)
to restore it later. The best place to use this methods are the lifecycle callbacks of an Activity
or Fragment
.
Constructor and Description |
---|
InMemoryOAuth2TokenStorage()
Creates a new, empty in-memory storage.
|
Modifier and Type | Method and Description |
---|---|
static InMemoryOAuth2TokenStorage |
readStorageFromBundle(android.os.Bundle bundle,
java.lang.String storageName)
Retrieve token storage from the specified bundle.
|
java.util.concurrent.Future<java.lang.Boolean> |
removeAllTokens()
Deletes all the tokens in this storage.
|
void |
saveStorageToBundle(android.os.Bundle bundle,
java.lang.String storageName)
Save token storage into the specified bundle.
|
java.util.concurrent.Future<java.lang.Boolean> |
saveTokens(java.lang.String tokenStorageKey,
OAuth2TokenWrapper tokens)
Saves the tokens carried by the specified wrapper for the given opaque token storage key.
|
java.util.concurrent.Future<OAuth2TokenWrapper> |
tokensForKey(java.lang.String tokenStorageKey)
Returns the token wrapper object for the specified opaque token storage key.
|
public InMemoryOAuth2TokenStorage()
public static InMemoryOAuth2TokenStorage readStorageFromBundle(android.os.Bundle bundle, java.lang.String storageName)
bundle
- bundle which contains the storage, can be nullstorageName
- storage name for retrieve the token storage, must be non-nullpublic java.util.concurrent.Future<OAuth2TokenWrapper> tokensForKey(java.lang.String tokenStorageKey)
OAuth2TokenStorage
tokensForKey
in interface OAuth2TokenStorage
tokenStorageKey
- the opaque token storage key to return the tokens for, must be non-nullpublic java.util.concurrent.Future<java.lang.Boolean> saveTokens(java.lang.String tokenStorageKey, OAuth2TokenWrapper tokens)
OAuth2TokenStorage
tokens
argument is null then the
tokens are deleted for the given key.saveTokens
in interface OAuth2TokenStorage
tokenStorageKey
- the opaque token storage key to save the tokens for, must be non-nulltokens
- the token wrapper whose contents are to be saved, can be nullpublic java.util.concurrent.Future<java.lang.Boolean> removeAllTokens()
OAuth2TokenStorage
removeAllTokens
in interface OAuth2TokenStorage
public void saveStorageToBundle(android.os.Bundle bundle, java.lang.String storageName)
bundle
- save storage to the bundle, can be nullstorageName
- storage name to save the token storage, must be non-null