Class UserAuthorizer (1.37.1)

publicclass UserAuthorizer

Handles an interactive 3-Legged-OAuth2 (3LO) user consent authorization.

Inheritance

java.lang.Object > UserAuthorizer

Static Methods

newBuilder()

publicstaticUserAuthorizer.BuildernewBuilder()
Returns
Type Description
UserAuthorizer.Builder

Methods

getAndStoreCredentialsFromCode(String userId, String code, URI baseUri)

publicUserCredentialsgetAndStoreCredentialsFromCode(StringuserId,Stringcode,URIbaseUri)

Exchanges an authorization code for tokens and stores them.

Parameters
Name Description
userId String

Application's identifier for the end user.

code String

Code returned from OAuth2 consent prompt.

baseUri URI

The URI to resolve the OAuth2 callback URI relative to.

Returns
Type Description
UserCredentials

UserCredentials instance created from the authorization code.

Exceptions
Type Description
IOException

An error from the server API call to get the tokens or store the tokens.

getAuthorizationUrl(String userId, String state, URI baseUri)

publicURLgetAuthorizationUrl(StringuserId,Stringstate,URIbaseUri)

Return a URL that performs the authorization consent prompt web UI.

Parameters
Name Description
userId String

Application's identifier for the end user.

state String

State that is passed on to the OAuth2 callback URI after the consent.

baseUri URI

The URI to resolve the OAuth2 callback URI relative to.

Returns
Type Description
URL

The URL that can be navigated or redirected to.

getAuthorizationUrl(String userId, String state, URI baseUri, Map<String,String> additionalParameters)

publicURLgetAuthorizationUrl(StringuserId,Stringstate,URIbaseUri,Map<String,String>additionalParameters)

Return a URL that performs the authorization consent prompt web UI.

Parameters
Name Description
userId String

Application's identifier for the end user.

state String

State that is passed on to the OAuth2 callback URI after the consent.

baseUri URI

The URI to resolve the OAuth2 callback URI relative to.

additionalParameters Map<String,String>

Additional query parameters to be added to the authorization URL.

Returns
Type Description
URL

The URL that can be navigated or redirected to.

getCallbackUri()

publicURIgetCallbackUri()

Returns the URI for implementation of the OAuth2 web callback.

Returns
Type Description
URI

The URI for the OAuth2 web callback.

getCallbackUri(URI baseUri)

publicURIgetCallbackUri(URIbaseUri)

Returns the URI for implementation of the OAuth2 web callback, optionally relative to the specified URI.

The callback URI is often relative to enable an application to be tested from more than one place so this can be used to resolve it relative to another URI.

Parameter
Name Description
baseUri URI

The URI to resolve the callback URI relative to.

Returns
Type Description
URI

The resolved URI.

getClientAuthenticationType()

publicUserAuthorizer.ClientAuthenticationTypegetClientAuthenticationType()

Returns the client authentication type as defined in RFC 7591.

Returns
Type Description
UserAuthorizer.ClientAuthenticationType

The ClientAuthenticationType

getClientId()

publicClientIdgetClientId()

Returns the Client ID user to identify the OAuth2 consent prompt.

Returns
Type Description
ClientId

The Client ID.

getCredentials(String userId)

publicUserCredentialsgetCredentials(StringuserId)

Attempts to retrieve credentials for the approved end user consent.

Parameter
Name Description
userId String

Application's identifier for the end user.

Returns
Type Description
UserCredentials

The loaded credentials or null if there are no valid approved credentials.

Exceptions
Type Description
IOException

If there is error retrieving or loading the credentials.

getCredentialsFromCode(String code, URI baseUri)

publicUserCredentialsgetCredentialsFromCode(Stringcode,URIbaseUri)

Returns a UserCredentials instance by exchanging an OAuth2 authorization code for tokens.

Parameters
Name Description
code String

Code returned from OAuth2 consent prompt.

baseUri URI

The URI to resolve the OAuth2 callback URI relative to.

Returns
Type Description
UserCredentials

the UserCredentials instance created from the authorization code.

Exceptions
Type Description
IOException

An error from the server API call to get the tokens.

getCredentialsFromCode(String code, URI baseUri, Map<String,String> additionalParameters)

publicUserCredentialsgetCredentialsFromCode(Stringcode,URIbaseUri,Map<String,String>additionalParameters)

Returns a UserCredentials instance by exchanging an OAuth2 authorization code for tokens.

Parameters
Name Description
code String

Code returned from OAuth2 consent prompt.

baseUri URI

The URI to resolve the OAuth2 callback URI relative to.

additionalParameters Map<String,String>

Additional parameters to be added to the post body of token endpoint request.

Returns
Type Description
UserCredentials

the UserCredentials instance created from the authorization code.

Exceptions
Type Description
IOException

An error from the server API call to get the tokens.

getScopes()

publicCollection<String>getScopes()

Returns the scopes defining the user consent.

Returns
Type Description
Collection<String>

The collection of scopes defining the user consent.

getTokenResponseFromAuthCodeExchange(String code, URI callbackUri, Map<String,String> additionalParameters)

publicUserAuthorizer.TokenResponseWithConfiggetTokenResponseFromAuthCodeExchange(Stringcode,URIcallbackUri,Map<String,String>additionalParameters)

Handles OAuth2 authorization code exchange and returns a TokenResponseWithConfig object containing the tokens and configuration details.

Parameters
Name Description
code String

The authorization code received from the OAuth2 authorization server.

callbackUri URI

The URI to which the authorization server redirected the user after granting authorization.

additionalParameters Map<String,String>

Additional parameters to include in the token exchange request.

Returns
Type Description
UserAuthorizer.TokenResponseWithConfig

A TokenResponseWithConfig object containing the access token, refresh token (if granted), and configuration details used in the OAuth flow.

Exceptions
Type Description
IOException

If an error occurs during the token exchange process.

getTokenStore()

publicTokenStoregetTokenStore()

Returns the implementation of a component for long term storage of tokens.

Returns
Type Description
TokenStore

The token storage implementation for long term storage of tokens.

monitorCredentials(String userId, UserCredentials credentials)

protectedvoidmonitorCredentials(StringuserId,UserCredentialscredentials)

Adds a listen to rewrite the credentials when the tokens are refreshed.

Parameters
Name Description
userId String

Application's identifier for the end user.

credentials UserCredentials

UserCredentials instance to listen to.

revokeAuthorization(String userId)

publicvoidrevokeAuthorization(StringuserId)

Revokes the authorization for tokens stored for the user.

Parameter
Name Description
userId String

Application's identifier for the end user.

Exceptions
Type Description
IOException

An error calling the revoke API or deleting the state.

storeCredentials(String userId, UserCredentials credentials)

publicvoidstoreCredentials(StringuserId,UserCredentialscredentials)

Puts the end user credentials in long term storage.

Parameters
Name Description
userId String

Application's identifier for the end user.

credentials UserCredentials

UserCredentials instance for the authorized consent.

Exceptions
Type Description
IOException

An error storing the credentials.

toBuilder()

publicUserAuthorizer.BuildertoBuilder()
Returns
Type Description
UserAuthorizer.Builder

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.