Class UserCredentials (1.40.0)

publicclass UserCredentialsextendsGoogleCredentialsimplementsIdTokenProvider

OAuth2 Credentials representing a user's identity and consent.

Inheritance

Object > Credentials > OAuth2Credentials > GoogleCredentials > UserCredentials

Implements

IdTokenProvider

Inherited Members

Static Methods

fromStream(InputStream credentialsStream)

publicstaticUserCredentialsfromStream(InputStreamcredentialsStream)

Returns credentials defined by a JSON file stream using the format supported by the Cloud SDK.

Parameter
Name Description
credentialsStream InputStream

the stream with the credential definition.

Returns
Type Description
UserCredentials

the credential defined by the credentialsStream.

Exceptions
Type Description
IOException

if the credential cannot be created from the stream.

fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory)

publicstaticUserCredentialsfromStream(InputStreamcredentialsStream,HttpTransportFactorytransportFactory)

Returns credentials defined by a JSON file stream using the format supported by the Cloud SDK.

Parameters
Name Description
credentialsStream InputStream

the stream with the credential definition.

transportFactory HttpTransportFactory

HTTP transport factory, creates the transport used to get access tokens.

Returns
Type Description
UserCredentials

the credential defined by the credentialsStream.

Exceptions
Type Description
IOException

if the credential cannot be created from the stream.

newBuilder()

publicstaticUserCredentials.BuildernewBuilder()
Returns
Type Description
UserCredentials.Builder

Methods

equals(Object obj)

publicbooleanequals(Objectobj)
Parameter
Name Description
obj Object
Returns
Type Description
boolean
Overrides

getClientId()

publicfinalStringgetClientId()

Returns client ID of the credential from the console.

Returns
Type Description
String

client ID

getClientSecret()

publicfinalStringgetClientSecret()

Returns client secret of the credential from the console.

Returns
Type Description
String

client secret

getMetricsCredentialType()

publicCredentialTypeForMetricsgetMetricsCredentialType()

Gets 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.

Returns
Type Description
CredentialTypeForMetrics
Overrides

getRefreshToken()

publicfinalStringgetRefreshToken()

Returns the refresh token resulting from a OAuth2 consent flow.

Returns
Type Description
String

refresh token

hashCode()

publicinthashCode()
Returns
Type Description
int
Overrides

idTokenWithAudience(String targetAudience, List<IdTokenProvider.Option> options)

publicIdTokenidTokenWithAudience(StringtargetAudience,List<IdTokenProvider.Option>options)

Returns a Google ID Token from the refresh token response.

Parameters
Name Description
targetAudience String

This can't be used for UserCredentials.

options List<Option>

list of Credential specific options for the token. Currently unused for UserCredentials.

Returns
Type Description
IdToken

IdToken object which includes the raw id_token, expiration and audience

Exceptions
Type Description
IOException

if the attempt to get an IdToken failed

refreshAccessToken()

publicAccessTokenrefreshAccessToken()

Refreshes the OAuth2 access token by getting a new access token from the refresh token

Returns
Type Description
AccessToken
Overrides
Exceptions
Type Description
IOException

save(String filePath)

publicvoidsave(StringfilePath)

Saves the end user credentials into the given file path.

Parameter
Name Description
filePath String

Path to file where to store the credentials

Exceptions
Type Description
IOException

An error storing the credentials.

toBuilder()

publicUserCredentials.BuildertoBuilder()
Returns
Type Description
UserCredentials.Builder
Overrides

toString()

publicStringtoString()
Returns
Type Description
String
Overrides

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.