public final class Auth
extends java.lang.Object
Provides methods to get tokens, retrieve the last authenticated user on the device, and sign-out users.
| Modifier and Type | Class and Description |
|---|---|
static class |
Auth.Builder
Builder class for
Auth objects. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getAppId() |
java.lang.String |
getAppSecret() |
java.lang.String |
getAppWebDomain() |
java.lang.String |
getBrowserPackage() |
Auth |
getCurrentUser() |
android.os.Bundle |
getCustomTabExtras() |
java.lang.String |
getIdentityProvider() |
java.lang.String |
getIdpIdentifier() |
java.util.Set<java.lang.String> |
getScopes() |
void |
getSession(android.app.Activity activity)
Use this method to get tokens for a user, the tokens are returned though the callback.
|
void |
getSessionWithoutWebUI()
Use this method to get tokens for a user, the tokens are returned though the callback.
|
java.lang.String |
getSignInRedirectUri() |
java.lang.String |
getSignOutRedirectUri() |
void |
getTokens(android.net.Uri uri)
Exchanges the Cognito Authentication Code for Cognito Tokens.
|
java.lang.String |
getUsername() |
java.lang.String |
getUserPoolId() |
void |
handleFlowCancelled()
Properly handles the event where a user cancels the auth flow before completing it.
|
boolean |
isAdvancedSecurityDataCollectionEnabled() |
boolean |
isAuthenticated() |
void |
release()
Release resources used by
Auth |
void |
setAdvancedSecurityDataCollection(boolean isEnabled)
It enables user context data collection.
|
void |
setAuthHandler(AuthHandler authHandler)
Reset the AuthHandler on the client.
|
void |
setBrowserPackage(java.lang.String browserPackage)
Update the browser package to use for launching a custom tab.
|
void |
setPersistenceEnabled(boolean isPersistenceEnabled)
Enable or disable persistence
|
Auth |
setUsername(java.lang.String username)
Set a username for the
Auth instance. |
void |
signOut()
Signs out the user.
|
void |
signOut(boolean clearLocalTokensOnly)
Sign out with options.
|
public void setAdvancedSecurityDataCollection(boolean isEnabled)
public boolean isAdvancedSecurityDataCollectionEnabled()
public void setPersistenceEnabled(boolean isPersistenceEnabled)
isPersistenceEnabled - flag if true indicates tokens are persisted.public void setBrowserPackage(java.lang.String browserPackage)
browserPackage - the browser package to use for launching a custom tab.public Auth getCurrentUser()
Auth after setting to the last authenticated user on
the device.public java.lang.String getUserPoolId()
public java.lang.String getAppWebDomain()
public java.lang.String getAppId()
public java.lang.String getAppSecret()
public java.util.Set<java.lang.String> getScopes()
Auth instance.public java.lang.String getUsername()
Auth instance.public java.lang.String getSignInRedirectUri()
Auth instance.public java.lang.String getSignOutRedirectUri()
Auth instance.public java.lang.String getBrowserPackage()
Auth instance.public java.lang.String getIdentityProvider()
Auth instance.public java.lang.String getIdpIdentifier()
Auth instance.public android.os.Bundle getCustomTabExtras()
Auth instance.public void getSession(android.app.Activity activity)
AuthHandler.onSuccess(AuthUserSession).
If a username is available, this method looks for valid cached tokens on the device.
If the cached token have expired and the refresh token (if available) is used to get new
tokens.
If valid tokens are not available locally or if the username is not set, Cognito Auth's
web interface is launched on Chrome Custom Tabs. The user credentials will be required to
authenticate.
Note: This SDK uses OAuth Code-Grant flow with PKCE, for authentication. To get
tokens after successful user authentication, the Amazon Cognito Auth returns the
authentication code through the redirect uri. Call getTokens(Uri) to
get tokens from the authentication code. Uri is the redirect uri with the
authentication code.
activity - Activity to launch custom tabs from and to listen for the intent completions.public void getSessionWithoutWebUI()
AuthHandler.onSuccess(AuthUserSession). If the tokens are not available, it will not
launch the browser to re-authenticate.
If a username is available, this method looks for valid cached tokens on the device. If the cached token have expired and the refresh token (if available) is used to get new tokens. If valid tokens are not available locally or if the username is not set, the error callback will be invoked. It will not launch a sign in experience.
public void setAuthHandler(AuthHandler authHandler)
authHandler - public void signOut()
Invokes Cognito Auth's web signout domain to clear cookies stored. If username is set, the local cached tokens are cleared.
public void signOut(boolean clearLocalTokensOnly)
clearLocalTokensOnly - true if signs out the user from the client,
but the session may still be alive from the browser.public boolean isAuthenticated()
True if a user has valid cached tokens.public void getTokens(android.net.Uri uri)
Call this method when the Chrome Custom tabs redirect to the your app Activity
after authentication. Pass the redirect uri as parameter, the redirect uri can can be found
in the Intent used to invoke your Activity.
uri - Required: Uri containing the redirect and authentication code.public void handleFlowCancelled()
public Auth setUsername(java.lang.String username)
Auth instance.username - Required: The username of the user in your Cognito User-Pool.Auth.public void release()
Auth