Class UserCredentials
java.lang.Object
com.google.auth.Credentials
com.google.auth.oauth2.OAuth2Credentials
com.google.auth.oauth2.GoogleCredentials
com.google.auth.oauth2.UserCredentials
- All Implemented Interfaces:
IdTokenProvider, QuotaProjectIdProvider, Serializable
OAuth2 Credentials representing a user's identity and consent.
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class OAuth2Credentials
OAuth2Credentials.AsyncRefreshResult, OAuth2Credentials.CacheState, OAuth2Credentials.CredentialsChangedListener, OAuth2Credentials.FutureCallbackToMetadataCallbackAdapter, OAuth2Credentials.OAuthValue, OAuth2Credentials.RefreshTask, OAuth2Credentials.RefreshTaskListenerNested classes/interfaces inherited from interface IdTokenProvider
IdTokenProvider.Option -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stringprivate final Stringprivate static final Stringprivate static final Stringprivate final Stringprivate static final longprivate final URIprivate HttpTransportFactoryprivate final StringFields inherited from class GoogleCredentials
GDCH_SERVICE_ACCOUNT_FILE_TYPE, QUOTA_PROJECT_ID_HEADER_KEY, quotaProjectId, SERVICE_ACCOUNT_FILE_TYPE, USER_FILE_TYPEFields inherited from class OAuth2Credentials
clock, DEFAULT_EXPIRATION_MARGIN, DEFAULT_REFRESH_MARGIN, lock, refreshTaskFields inherited from class Credentials
GOOGLE_DEFAULT_UNIVERSE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateUserCredentials(UserCredentials.Builder builder) Internal constructor -
Method Summary
Modifier and TypeMethodDescriptionprivate com.google.api.client.util.GenericDataDoes refresh access token requestboolean(package private) static UserCredentialsfromJson(Map<String, Object> json, HttpTransportFactory transportFactory) Returns user credentials defined by JSON contents using the format supported by the Cloud SDK.static UserCredentialsfromStream(InputStream credentialsStream) Returns credentials defined by a JSON file stream using the format supported by the Cloud SDK.static UserCredentialsfromStream(InputStream credentialsStream, HttpTransportFactory transportFactory) Returns credentials defined by a JSON file stream using the format supported by the Cloud SDK.final StringReturns client ID of the credential from the console.final StringReturns client secret of the credential from the console.Gets the credential type used for internal metrics header.final StringReturns the refresh token resulting from a OAuth2 consent flow.private InputStreamReturns the instance of InputStream containing the following user credentials in JSON format: - RefreshToken - ClientId - ClientSecret - ServerTokenUriinthashCode()idTokenWithAudience(String targetAudience, List<IdTokenProvider.Option> options) Returns a Google ID Token from the refresh token response.static UserCredentials.Builderprivate voidreadObject(ObjectInputStream input) Refreshes the OAuth2 access token by getting a new access token from the refresh tokenvoidSaves the end user credentials into the given file path.toString()Methods inherited from class GoogleCredentials
addQuotaProjectIdToRequestMetadata, create, create, createDelegated, createScoped, createScoped, createScoped, createScopedRequired, createWithCustomRetryStrategy, createWithQuotaProject, getAdditionalHeaders, getApplicationDefault, getApplicationDefault, getQuotaProjectId, getUniverseDomain, isDefaultUniverseDomain, isExplicitUniverseDomain, toStringHelperMethods inherited from class OAuth2Credentials
addChangeListener, getAccessToken, getAuthenticationType, getExpirationMargin, getFromServiceLoader, getRefreshMargin, getRequestMetadata, getRequestMetadata, getRequestMetadataInternal, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, refreshIfExpired, removeChangeListenerMethods inherited from class Credentials
blockingGetToCallback, getRequestMetadata
-
Field Details
-
GRANT_TYPE
- See Also:
-
PARSE_ERROR_PREFIX
- See Also:
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
clientId
-
clientSecret
-
refreshToken
-
tokenServerUri
-
transportFactoryClassName
-
transportFactory
-
-
Constructor Details
-
UserCredentials
Internal constructor- Parameters:
builder- A builder forUserCredentialsSeeUserCredentials.Builder
-
-
Method Details
-
getMetricsCredentialType
Description copied from class:CredentialsGets the credential type used for internal metrics header.The default is
CredentialTypeForMetrics.DO_NOT_SEND. For a credential that is established to track for metrics, this default should be overridden.- Overrides:
getMetricsCredentialTypein classCredentials- Returns:
- a enum value for credential type
-
fromJson
static UserCredentials fromJson(Map<String, Object> json, HttpTransportFactory transportFactory) throws IOExceptionReturns user credentials defined by JSON contents using the format supported by the Cloud SDK.- Parameters:
json- a map from the JSON representing the credentials.transportFactory- HTTP transport factory, creates the transport used to get access tokens.- Returns:
- the credentials defined by the JSON.
- Throws:
IOException- if the credential cannot be created from the JSON.
-
fromStream
Returns credentials defined by a JSON file stream using the format supported by the Cloud SDK.- Parameters:
credentialsStream- the stream with the credential definition.- Returns:
- the credential defined by the credentialsStream.
- Throws:
IOException- if the credential cannot be created from the stream.
-
fromStream
public static UserCredentials fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory) throws IOException Returns credentials defined by a JSON file stream using the format supported by the Cloud SDK.- Parameters:
credentialsStream- the stream with the credential definition.transportFactory- HTTP transport factory, creates the transport used to get access tokens.- Returns:
- the credential defined by the credentialsStream.
- Throws:
IOException- if the credential cannot be created from the stream.
-
refreshAccessToken
Refreshes the OAuth2 access token by getting a new access token from the refresh token- Overrides:
refreshAccessTokenin classOAuth2Credentials- Returns:
- never
- Throws:
IOException
-
idTokenWithAudience
public IdToken idTokenWithAudience(String targetAudience, List<IdTokenProvider.Option> options) throws IOException Returns a Google ID Token from the refresh token response.- Specified by:
idTokenWithAudiencein interfaceIdTokenProvider- Parameters:
targetAudience- This can't be used for UserCredentials.options- list of Credential specific options for the token. Currently unused for UserCredentials.- Returns:
- IdToken object which includes the raw id_token, expiration and audience
- Throws:
IOException- if the attempt to get an IdToken failed
-
getClientId
Returns client ID of the credential from the console.- Returns:
- client ID
-
getClientSecret
Returns client secret of the credential from the console.- Returns:
- client secret
-
getRefreshToken
Returns the refresh token resulting from a OAuth2 consent flow.- Returns:
- refresh token
-
doRefreshAccessToken
Does refresh access token request- Returns:
- Refresh token response data
- Throws:
IOException
-
getUserCredentialsStream
Returns the instance of InputStream containing the following user credentials in JSON format: - RefreshToken - ClientId - ClientSecret - ServerTokenUri- Returns:
- user credentials stream
- Throws:
IOException
-
save
Saves the end user credentials into the given file path.- Parameters:
filePath- Path to file where to store the credentials- Throws:
IOException- An error storing the credentials.
-
hashCode
public int hashCode()- Overrides:
hashCodein classGoogleCredentials
-
toString
- Overrides:
toStringin classGoogleCredentials
-
equals
- Overrides:
equalsin classGoogleCredentials
-
readObject
- Throws:
IOExceptionClassNotFoundException
-
newBuilder
-
toBuilder
- Overrides:
toBuilderin classGoogleCredentials
-