Class OAuth2Credentials (1.38.0)
Stay organized with collections
Save and categorize content based on your preferences.
publicclass OAuth2CredentialsextendsCredentialsBase type for Credentials using OAuth2.
Inherited Members
Static Methods
<T>getFromServiceLoader(Class<? extends T> clazz, T defaultInstance)
publicstaticT<T>getFromServiceLoader(Class<?extendsT>clazz,TdefaultInstance)Returns the first service provider from the given service loader.
| Parameters | |
|---|---|
| Name | Description |
clazz |
Class<? extends T>The class of the service provider to load. |
defaultInstance |
TThe default instance to return if no service providers are found. |
| Returns | |
|---|---|
| Type | Description |
T |
The first service provider from the service loader, or the |
<T>newInstance(String className)
protectedstaticT<T>newInstance(StringclassName)| Parameter | |
|---|---|
| Name | Description |
className |
String |
| Returns | |
|---|---|
| Type | Description |
T |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
ClassNotFoundException |
|
create(AccessToken accessToken)
publicstaticOAuth2Credentialscreate(AccessTokenaccessToken)Returns the credentials instance from the given access token.
| Parameter | |
|---|---|
| Name | Description |
accessToken |
AccessToken the access token |
| Returns | |
|---|---|
| Type | Description |
OAuth2Credentials |
the credentials instance |
newBuilder()
publicstaticOAuth2Credentials.BuildernewBuilder()| Returns | |
|---|---|
| Type | Description |
OAuth2Credentials.Builder |
|
Constructors
OAuth2Credentials()
protectedOAuth2Credentials()Default constructor.
OAuth2Credentials(AccessToken accessToken)
protectedOAuth2Credentials(AccessTokenaccessToken)Constructor with explicit access token.
| Parameter | |
|---|---|
| Name | Description |
accessToken |
AccessToken initial or temporary access token |
OAuth2Credentials(AccessToken accessToken, Duration refreshMargin, Duration expirationMargin)
protectedOAuth2Credentials(AccessTokenaccessToken,DurationrefreshMargin,DurationexpirationMargin)| Parameters | |
|---|---|
| Name | Description |
accessToken |
AccessToken |
refreshMargin |
Duration |
expirationMargin |
Duration |
Methods
addChangeListener(OAuth2Credentials.CredentialsChangedListener listener)
publicfinalvoidaddChangeListener(OAuth2Credentials.CredentialsChangedListenerlistener)Adds a listener that is notified when the Credentials data changes.
This is called when token content changes, such as when the access token is refreshed. This is typically used by code caching the access token.
| Parameter | |
|---|---|
| Name | Description |
listener |
OAuth2Credentials.CredentialsChangedListener the listener to be added |
equals(Object obj)
publicbooleanequals(Objectobj)| Parameter | |
|---|---|
| Name | Description |
obj |
Object |
| Returns | |
|---|---|
| Type | Description |
boolean |
|
getAccessToken()
publicfinalAccessTokengetAccessToken()Returns the cached access token.
If not set, you should call #refresh() to fetch and cache an access token.
| Returns | |
|---|---|
| Type | Description |
AccessToken |
The cached access token. |
getAdditionalHeaders()
protectedMap<String,List<String>>getAdditionalHeaders()Provide additional headers to return as request metadata.
| Returns | |
|---|---|
| Type | Description |
Map<String,List<String>> |
additional headers |
getAuthenticationType()
publicStringgetAuthenticationType()A constant string name describing the authentication technology.
E.g. "OAuth2", "SSL". For use by the transport layer to determine whether it supports the type of authentication in the case where Credentials#hasRequestMetadataOnly is false. Also serves as a debugging helper.
| Returns | |
|---|---|
| Type | Description |
String |
|
getRequestMetadata(URI uri)
publicMap<String,List<String>>getRequestMetadata(URIuri)Provide the request metadata by ensuring there is a current access token and providing it as an authorization bearer token.
| Parameter | |
|---|---|
| Name | Description |
uri |
URI |
| Returns | |
|---|---|
| Type | Description |
Map<String,List<String>> |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
getRequestMetadata(URI uri, Executor executor, RequestMetadataCallback callback)
publicvoidgetRequestMetadata(URIuri,Executorexecutor,RequestMetadataCallbackcallback)Get the current request metadata without blocking.
This should be called by the transport layer on each request, and the data should be populated in headers or other context. The implementation can either call the callback inline or asynchronously. Either way it should never block in this method. The executor is provided for tasks that may block.
The default implementation will just call #getRequestMetadata(URI) then the callback from the given executor.
The convention for handling binary data is for the key in the returned map to end with
"-bin" and for the corresponding values to be base64 encoded.
| Parameters | |
|---|---|
| Name | Description |
uri |
URI |
executor |
Executor |
callback |
RequestMetadataCallback |
getRequestMetadataInternal()
protectedMap<String,List<String>>getRequestMetadataInternal()| Returns | |
|---|---|
| Type | Description |
Map<String,List<String>> |
|
hasRequestMetadata()
publicbooleanhasRequestMetadata()Whether the credentials have metadata entries that should be added to each request.
This should be called by the transport layer to see if Credentials#getRequestMetadata should be used for each request.
| Returns | |
|---|---|
| Type | Description |
boolean |
|
hasRequestMetadataOnly()
publicbooleanhasRequestMetadataOnly()Indicates whether or not the Auth mechanism works purely by including request metadata.
This is meant for the transport layer. If this is true a transport does not need to take actions other than including the request metadata. If this is false, a transport must specifically know about the authentication technology to support it, and should fail to accept the credentials otherwise.
| Returns | |
|---|---|
| Type | Description |
boolean |
|
hashCode()
publicinthashCode()| Returns | |
|---|---|
| Type | Description |
int |
|
refresh()
publicvoidrefresh()Request a new token regardless of the current token state. If the current token is not expired, it will still be returned during the refresh.
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
refreshAccessToken()
publicAccessTokenrefreshAccessToken()Method to refresh the access token according to the specific type of credentials.
Throws IllegalStateException if not overridden since direct use of OAuth2Credentials is only for temporary or non-refreshing access tokens.
| Returns | |
|---|---|
| Type | Description |
AccessToken |
never |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
always. OAuth2Credentials does not support refreshing the access token. An instance with a new access token or a derived type that supports refreshing should be used instead. |
refreshIfExpired()
publicvoidrefreshIfExpired()Refresh these credentials only if they have expired or are expiring imminently.
| Exceptions | |
|---|---|
| Type | Description |
IOException |
during token refresh. |
removeChangeListener(OAuth2Credentials.CredentialsChangedListener listener)
publicfinalvoidremoveChangeListener(OAuth2Credentials.CredentialsChangedListenerlistener)Removes a listener that was added previously.
| Parameter | |
|---|---|
| Name | Description |
listener |
OAuth2Credentials.CredentialsChangedListener The listener to be removed. |
toBuilder()
publicOAuth2Credentials.BuildertoBuilder()| Returns | |
|---|---|
| Type | Description |
OAuth2Credentials.Builder |
|
toString()
publicStringtoString()| Returns | |
|---|---|
| Type | Description |
String |
|