Class UserAuthorizer (1.3.0)

publicclass UserAuthorizer

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

Inheritance

java.lang.Object > UserAuthorizer

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

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.

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.

getScopes()

publicCollection<String>getScopes()

Returns the scopes defining the user consent.

Returns
Type Description
Collection<String>

The collection of scopes defining the user consent.

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.

newBuilder()

publicstaticUserAuthorizer.BuildernewBuilder()
Returns
Type Description

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

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.