Package com.google.auth.oauth2
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
public class UserCredentials extends GoogleCredentials implements IdTokenProvider
OAuth2 Credentials representing a user's identity and consent.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUserCredentials.Builder-
Nested classes/interfaces inherited from class com.google.auth.oauth2.OAuth2Credentials
OAuth2Credentials.CredentialsChangedListener
-
Nested classes/interfaces inherited from interface com.google.auth.oauth2.IdTokenProvider
IdTokenProvider.Option
-
-
Field Summary
-
Fields inherited from class com.google.auth.oauth2.GoogleCredentials
quotaProjectId
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)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.StringgetClientId()Returns client ID of the credential from the console.StringgetClientSecret()Returns client secret of the credential from the console.StringgetRefreshToken()Returns the refresh token resulting from a OAuth2 consent flow.inthashCode()IdTokenidTokenWithAudience(String targetAudience, List<IdTokenProvider.Option> options)Returns a Google ID Token from the refresh token response.static UserCredentials.BuildernewBuilder()AccessTokenrefreshAccessToken()Refreshes the OAuth2 access token by getting a new access token from the refresh tokenvoidsave(String filePath)Saves the end user credentials into the given file path.UserCredentials.BuildertoBuilder()StringtoString()-
Methods inherited from class com.google.auth.oauth2.GoogleCredentials
create, createDelegated, createScoped, createScoped, createScoped, createScopedRequired, createWithCustomRetryStrategy, createWithQuotaProject, getAdditionalHeaders, getApplicationDefault, getApplicationDefault, getQuotaProjectId
-
Methods inherited from class com.google.auth.oauth2.OAuth2Credentials
addChangeListener, getAccessToken, getAuthenticationType, getFromServiceLoader, getRequestMetadata, getRequestMetadata, getRequestMetadataInternal, hasRequestMetadata, hasRequestMetadataOnly, newInstance, refresh, refreshIfExpired, removeChangeListener
-
Methods inherited from class com.google.auth.Credentials
blockingGetToCallback, getRequestMetadata
-
-
-
-
Method Detail
-
fromStream
public static UserCredentials fromStream(InputStream credentialsStream) 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.- 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
public AccessToken refreshAccessToken() throws IOException
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
public final String getClientId()
Returns client ID of the credential from the console.- Returns:
- client ID
-
getClientSecret
public final String getClientSecret()
Returns client secret of the credential from the console.- Returns:
- client secret
-
getRefreshToken
public final String getRefreshToken()
Returns the refresh token resulting from a OAuth2 consent flow.- Returns:
- refresh token
-
save
public void save(String filePath) throws IOException
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 classOAuth2Credentials
-
toString
public String toString()
- Overrides:
toStringin classOAuth2Credentials
-
equals
public boolean equals(Object obj)
- Overrides:
equalsin classOAuth2Credentials
-
newBuilder
public static UserCredentials.Builder newBuilder()
-
toBuilder
public UserCredentials.Builder toBuilder()
- Overrides:
toBuilderin classGoogleCredentials
-
-