Class UserAuthorizer (1.27.0)

public class UserAuthorizer

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

Inheritance

java.lang.Object > UserAuthorizer

Static Methods

newBuilder()

public static UserAuthorizer.Builder newBuilder()
Returns
Type Description
UserAuthorizer.Builder

Methods

getAndStoreCredentialsFromCode(String userId, String code, URI baseUri)

public UserCredentials getAndStoreCredentialsFromCode(String userId, String code, URI baseUri)

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)

public URL getAuthorizationUrl(String userId, String state, URI baseUri)

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)

public URL getAuthorizationUrl(String userId, String state, URI baseUri, 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()

public URI getCallbackUri()

Returns the URI for implementation of the OAuth2 web callback.

Returns
Type Description
URI

The URI for the OAuth2 web callback.

getCallbackUri(URI baseUri)

public URI getCallbackUri(URI baseUri)

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()

public UserAuthorizer.ClientAuthenticationType getClientAuthenticationType()

Returns the client authentication type as defined in RFC 7591.

Returns
Type Description
UserAuthorizer.ClientAuthenticationType

The ClientAuthenticationType

getClientId()

public ClientId getClientId()

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

Returns
Type Description
ClientId

The Client ID.

getCredentials(String userId)

public UserCredentials getCredentials(String userId)

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)

public UserCredentials getCredentialsFromCode(String code, URI baseUri)

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)

public UserCredentials getCredentialsFromCode(String code, URI baseUri, 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()

public Collection<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)

public UserAuthorizer.TokenResponseWithConfig getTokenResponseFromAuthCodeExchange(String code, URI callbackUri, 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()

public TokenStore getTokenStore()

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)

protected void monitorCredentials(String userId, UserCredentials credentials)

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)

public void revokeAuthorization(String userId)

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)

public void storeCredentials(String userId, UserCredentials credentials)

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()

public UserAuthorizer.Builder toBuilder()
Returns
Type Description
UserAuthorizer.Builder