public class UserAuthorizer extends Object
Modifier and Type | Class and Description |
---|---|
static class |
UserAuthorizer.Builder |
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 an URL that performs the authorization consent prompt web UI.
|
URL |
getAuthorizationUrl(String userId,
String state,
URI baseUri,
Map<String,String> additionalParameters)
Return an 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.
|
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.
|
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 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 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 © 2023 Google. All rights reserved.