public class UserAuthorizer extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
UserAuthorizer.Builder |
static class |
UserAuthorizer.ClientAuthenticationType
Represents the client authentication types as specified in RFC 7591.
|
static class |
UserAuthorizer.TokenResponseWithConfig
Represents the response from an OAuth token exchange, including configuration details used to
initiate the flow.
|
| Modifier and Type | Method and Description |
|---|---|
UserCredentials |
getAndStoreCredentialsFromCode(String userId,
String code,
URI baseUri)
Exchanges an authorization code for tokens and stores them.
|
URL |
getAuthorizationUrl(String userId,
String state,
URI baseUri)
Return a URL that performs the authorization consent prompt web UI.
|
URL |
getAuthorizationUrl(String userId,
String state,
URI baseUri,
Map<String,String> additionalParameters)
Return a URL that performs the authorization consent prompt web UI.
|
URI |
getCallbackUri()
Returns the URI for implementation of the OAuth2 web callback.
|
URI |
getCallbackUri(URI baseUri)
Returns the URI for implementation of the OAuth2 web callback, optionally relative to the
specified URI.
|
UserAuthorizer.ClientAuthenticationType |
getClientAuthenticationType()
Returns the client authentication type as defined in RFC 7591.
|
ClientId |
getClientId()
Returns the Client ID user to identify the OAuth2 consent prompt.
|
UserCredentials |
getCredentials(String userId)
Attempts to retrieve credentials for the approved end user consent.
|
UserCredentials |
getCredentialsFromCode(String code,
URI baseUri)
Returns a UserCredentials instance by exchanging an OAuth2 authorization code for tokens.
|
UserCredentials |
getCredentialsFromCode(String code,
URI baseUri,
Map<String,String> additionalParameters)
Returns a UserCredentials instance by exchanging an OAuth2 authorization code for tokens.
|
Collection<String> |
getScopes()
Returns the scopes defining the user consent.
|
UserAuthorizer.TokenResponseWithConfig |
getTokenResponseFromAuthCodeExchange(String code,
URI callbackUri,
Map<String,String> additionalParameters)
Handles OAuth2 authorization code exchange and returns a
UserAuthorizer.TokenResponseWithConfig object
containing the tokens and configuration details. |
TokenStore |
getTokenStore()
Returns the implementation of a component for long term storage of tokens.
|
protected void |
monitorCredentials(String userId,
UserCredentials credentials)
Adds a listen to rewrite the credentials when the tokens are refreshed.
|
static UserAuthorizer.Builder |
newBuilder() |
void |
revokeAuthorization(String userId)
Revokes the authorization for tokens stored for the user.
|
void |
storeCredentials(String userId,
UserCredentials credentials)
Puts the end user credentials in long term storage.
|
UserAuthorizer.Builder |
toBuilder() |
public ClientId getClientId()
public Collection<String> getScopes()
public URI getCallbackUri()
public URI getCallbackUri(URI baseUri)
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.
baseUri - The URI to resolve the callback URI relative to.public TokenStore getTokenStore()
public UserAuthorizer.ClientAuthenticationType getClientAuthenticationType()
UserAuthorizer.ClientAuthenticationTypepublic URL getAuthorizationUrl(String userId, String state, URI baseUri)
userId - Application's identifier for the end user.state - State that is passed on to the OAuth2 callback URI after the consent.baseUri - The URI to resolve the OAuth2 callback URI relative to.public URL getAuthorizationUrl(String userId, String state, URI baseUri, Map<String,String> additionalParameters)
userId - Application's identifier for the end user.state - State that is passed on to the OAuth2 callback URI after the consent.baseUri - The URI to resolve the OAuth2 callback URI relative to.additionalParameters - Additional query parameters to be added to the authorization URL.public UserCredentials getCredentials(String userId) throws IOException
userId - Application's identifier for the end user.IOException - If there is error retrieving or loading the credentials.public UserCredentials getCredentialsFromCode(String code, URI baseUri) throws IOException
code - Code returned from OAuth2 consent prompt.baseUri - The URI to resolve the OAuth2 callback URI relative to.IOException - An error from the server API call to get the tokens.public UserCredentials getCredentialsFromCode(String code, URI baseUri, Map<String,String> additionalParameters) throws IOException
code - Code returned from OAuth2 consent prompt.baseUri - The URI to resolve the OAuth2 callback URI relative to.additionalParameters - Additional parameters to be added to the post body of token
endpoint request.IOException - An error from the server API call to get the tokens.public UserAuthorizer.TokenResponseWithConfig getTokenResponseFromAuthCodeExchange(String code, URI callbackUri, Map<String,String> additionalParameters) throws IOException
UserAuthorizer.TokenResponseWithConfig object
containing the tokens and configuration details.code - The authorization code received from the OAuth2 authorization server.callbackUri - The URI to which the authorization server redirected the user after granting
authorization.additionalParameters - Additional parameters to include in the token exchange request.UserAuthorizer.TokenResponseWithConfig object containing the access token, refresh token (if
granted), and configuration details used in the OAuth flow.IOException - If an error occurs during the token exchange process.public UserCredentials getAndStoreCredentialsFromCode(String userId, String code, URI baseUri) throws IOException
userId - Application's identifier for the end user.code - Code returned from OAuth2 consent prompt.baseUri - The URI to resolve the OAuth2 callback URI relative to.IOException - An error from the server API call to get the tokens or store the tokens.public void revokeAuthorization(String userId) throws IOException
userId - Application's identifier for the end user.IOException - An error calling the revoke API or deleting the state.public void storeCredentials(String userId, UserCredentials credentials) throws IOException
userId - Application's identifier for the end user.credentials - UserCredentials instance for the authorized consent.IOException - An error storing the credentials.protected void monitorCredentials(String userId, UserCredentials credentials)
userId - Application's identifier for the end user.credentials - UserCredentials instance to listen to.public static UserAuthorizer.Builder newBuilder()
public UserAuthorizer.Builder toBuilder()
Copyright © 2026 Google. All rights reserved.