Class UserAuthorizer (1.18.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
TypeDescription
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
NameDescription
userIdString

Application's identifier for the end user.

codeString

Code returned from OAuth2 consent prompt.

baseUriURI

The URI to resolve the OAuth2 callback URI relative to.

Returns
TypeDescription
UserCredentials

UserCredentials instance created from the authorization code.

Exceptions
TypeDescription
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 an URL that performs the authorization consent prompt web UI.

Parameters
NameDescription
userIdString

Application's identifier for the end user.

stateString

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

baseUriURI

The URI to resolve the OAuth2 callback URI relative to.

Returns
TypeDescription
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 an URL that performs the authorization consent prompt web UI.

Parameters
NameDescription
userIdString

Application's identifier for the end user.

stateString

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

baseUriURI

The URI to resolve the OAuth2 callback URI relative to.

additionalParametersMap<String,String>

Additional query parameters to be added to the authorization URL.

Returns
TypeDescription
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
TypeDescription
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
NameDescription
baseUriURI

The URI to resolve the callback URI relative to.

Returns
TypeDescription
URI

The resolved URI.

getClientId()

public ClientId getClientId()

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

Returns
TypeDescription
ClientId

The Client ID.

getCredentials(String userId)

public UserCredentials getCredentials(String userId)

Attempts to retrieve credentials for the approved end user consent.

Parameter
NameDescription
userIdString

Application's identifier for the end user.

Returns
TypeDescription
UserCredentials

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

Exceptions
TypeDescription
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
NameDescription
codeString

Code returned from OAuth2 consent prompt.

baseUriURI

The URI to resolve the OAuth2 callback URI relative to.

Returns
TypeDescription
UserCredentials

the UserCredentials instance created from the authorization code.

Exceptions
TypeDescription
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
NameDescription
codeString

Code returned from OAuth2 consent prompt.

baseUriURI

The URI to resolve the OAuth2 callback URI relative to.

additionalParametersMap<String,String>

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

Returns
TypeDescription
UserCredentials

the UserCredentials instance created from the authorization code.

Exceptions
TypeDescription
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
TypeDescription
Collection<String>

The collection of scopes defining the user consent.

getTokenStore()

public TokenStore getTokenStore()

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

Returns
TypeDescription
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
NameDescription
userIdString

Application's identifier for the end user.

credentialsUserCredentials

UserCredentials instance to listen to.

revokeAuthorization(String userId)

public void revokeAuthorization(String userId)

Revokes the authorization for tokens stored for the user.

Parameter
NameDescription
userIdString

Application's identifier for the end user.

Exceptions
TypeDescription
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
NameDescription
userIdString

Application's identifier for the end user.

credentialsUserCredentials

UserCredentials instance for the authorized consent.

Exceptions
TypeDescription
IOException

An error storing the credentials.

toBuilder()

public UserAuthorizer.Builder toBuilder()
Returns
TypeDescription
UserAuthorizer.Builder