Class UserCredentials (1.6.1)

public class UserCredentials extends GoogleCredentials implements QuotaProjectIdProvider, IdTokenProvider

OAuth2 Credentials representing a user's identity and consent.

Inheritance

Object > Credentials > OAuth2Credentials > GoogleCredentials > UserCredentials

Static Methods

fromStream(InputStream credentialsStream)

public static UserCredentials fromStream(InputStream credentialsStream)

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

Parameter
NameDescription
credentialsStreamInputStream

the stream with the credential definition.

Returns
TypeDescription
UserCredentials

the credential defined by the credentialsStream.

Exceptions
TypeDescription
IOException

if the credential cannot be created from the stream.

fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory)

public static UserCredentials fromStream(InputStream credentialsStream, HttpTransportFactory transportFactory)

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

Parameters
NameDescription
credentialsStreamInputStream

the stream with the credential definition.

transportFactoryHttpTransportFactory

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

Returns
TypeDescription
UserCredentials

the credential defined by the credentialsStream.

Exceptions
TypeDescription
IOException

if the credential cannot be created from the stream.

newBuilder()

public static UserCredentials.Builder newBuilder()
Returns
TypeDescription
UserCredentials.Builder

Methods

equals(Object obj)

public boolean equals(Object obj)
Parameter
NameDescription
objObject
Returns
TypeDescription
boolean
Overrides

getAdditionalHeaders()

protected Map<String,List<String>> getAdditionalHeaders()

Provide additional headers to return as request metadata.

Returns
TypeDescription
Map<String,List<String>>
Overrides

getClientId()

public final String getClientId()

Returns client ID of the credential from the console.

Returns
TypeDescription
String

client ID

getClientSecret()

public final String getClientSecret()

Returns client secret of the credential from the console.

Returns
TypeDescription
String

client secret

getQuotaProjectId()

public String getQuotaProjectId()
Returns
TypeDescription
String

getRefreshToken()

public final String getRefreshToken()

Returns the refresh token resulting from a OAuth2 consent flow.

Returns
TypeDescription
String

refresh token

hashCode()

public int hashCode()
Returns
TypeDescription
int
Overrides

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

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

Returns a Google ID Token from the refresh token response.

Parameters
NameDescription
targetAudienceString

This can't be used for UserCredentials.

optionsList<Option>

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

Returns
TypeDescription
IdToken

IdToken object which includes the raw id_token, expiration and audience

Exceptions
TypeDescription
IOException

if the attempt to get an IdToken failed

refreshAccessToken()

public AccessToken refreshAccessToken()

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

Returns
TypeDescription
AccessToken
Overrides Exceptions
TypeDescription
IOException

save(String filePath)

public void save(String filePath)

Saves the end user credentials into the given file path.

Parameter
NameDescription
filePathString

Path to file where to store the credentials

Exceptions
TypeDescription
IOException

An error storing the credentials.

toBuilder()

public UserCredentials.Builder toBuilder()
Returns
TypeDescription
UserCredentials.Builder
Overrides

toString()

public String toString()
Returns
TypeDescription
String
Overrides