public class AuthClient
extends java.lang.Object
Auth.
Encapsulates user level operations, tokens AuthUserSession, handles
token caching, and token refresh.
Manages Cognito-Web user screens.
| Modifier and Type | Field and Description |
|---|---|
static int |
CUSTOM_TABS_ACTIVITY_CODE
A random code the custom tabs activity is launched under.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AuthClient(android.content.Context context,
Auth pool)
Constructs
AuthClient with no user name. |
protected |
AuthClient(android.content.Context context,
Auth pool,
java.lang.String username)
Constructs an instance of the Cognito User with username.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
getSession(boolean showSignInIfExpired,
android.app.Activity activity)
Launches user authentication screen and returns a redirect Uri through an
Intent. |
protected void |
getSession(boolean showSignInIfExpired,
android.app.Activity activity,
java.lang.String browserPackage)
Launches user authentication screen and returns a redirect Uri through an
Intent. |
void |
getTokens(android.net.Uri uri)
Exchanges code in the Uri for with Cognito JWT.
|
protected java.lang.String |
getUsername() |
void |
handleCustomTabsCancelled()
Properly handles the event where the user cancels out of the custom tabs auth flow either by closing it
or navigating back away from it.
|
boolean |
isAuthenticated() |
protected void |
setUserHandler(AuthHandler handler)
Set callback handler for
AuthClient. |
protected void |
setUsername(java.lang.String username)
Sets username.
|
void |
signOut()
Signs-out a user.
|
void |
signOut(boolean clearLocalTokensOnly)
Signs-out a user.
|
void |
signOut(boolean clearLocalTokensOnly,
java.lang.String browserPackage)
Signs-out a user.
|
void |
signOut(java.lang.String browserPackage)
Signs-out a user.
|
void |
unbindServiceConnection()
Unbind
mCustomTabsServiceConnection |
public static final int CUSTOM_TABS_ACTIVITY_CODE
protected AuthClient(android.content.Context context,
Auth pool)
AuthClient with no user name.context - Required: The android application Context.pool - Required: A reference to the parent, Auth.protected AuthClient(android.content.Context context,
Auth pool,
java.lang.String username)
context - Required: The android application Context.pool - Required: A reference to the parent, Auth.username - Required: The username of the user in the Cognito User-Pool.protected void setUserHandler(AuthHandler handler)
AuthClient.handler - Required: AuthHandler.protected void setUsername(java.lang.String username)
username - Required: Username as a String.protected void getSession(boolean showSignInIfExpired,
android.app.Activity activity)
Intent.
Checks for cached, valid tokens and launches the Cognito Web UI if no valid tokens are
found. This method uses PKCE for authentication. This SDK, therefore, uses code-grant flow
to authenticate user. The proof-key and a state is generated and its hash is used in added
as query parameters to create the authentication FQDN.
The state value set this method is used to temporarily cache the proof-key on the device.
To exchange the code for tokens, the Auth.getTokens(Uri) method will use the
state in the redirect uri to fetch the stored proof-key.
showSignInIfExpired - true if the web UI should launch when the session is expiredactivity - The activity to launch the sign in experience from.
This must not be null when showSignInIfExpired is true.protected void getSession(boolean showSignInIfExpired,
android.app.Activity activity,
java.lang.String browserPackage)
Intent.
Checks for cached, valid tokens and launches the Cognito Web UI if no valid tokens are
found. This method uses PKCE for authentication. This SDK, therefore, uses code-grant flow
to authenticate user. The proof-key and a state is generated and its hash is used in added
as query parameters to create the authentication FQDN.
The state value set this method is used to temporarily cache the proof-key on the device.
To exchange the code for tokens, the Auth.getTokens(Uri) method will use the
state in the redirect uri to fetch the stored proof-key.
showSignInIfExpired - true if the web UI should launch when the session is expiredactivity - The activity to launch the sign in experience from.
This must not be null when showSignInIfExpired is true.browserPackage - String specifying the browser package to launch the specified url.protected java.lang.String getUsername()
public void signOut()
Clears cached tokens for the user. Launches the sign-out Cognito web end-point to clear all Cognito Auth cookies stored by Chrome.
public void signOut(java.lang.String browserPackage)
Clears cached tokens for the user. Launches the sign-out Cognito web end-point to clear all Cognito Auth cookies stored by Chrome.
browserPackage - String specifying the browser package to launch the specified url.public void signOut(boolean clearLocalTokensOnly)
Clears cached tokens for the user. Launches the sign-out Cognito web end-point to clear all Cognito Auth cookies stored by Chrome.
clearLocalTokensOnly - true if signs out the user from the client,
but the session may still be alive from the browser.public void signOut(boolean clearLocalTokensOnly,
java.lang.String browserPackage)
Launches the sign-out Cognito web end-point to clear all Cognito Auth cookies stored by Chrome. Cached tokens will be deleted if sign-out redirect is completed.
clearLocalTokensOnly - true if signs out the user from the client,
but the session may still be alive from the browser.browserPackage - String specifying the browser package to launch the specified url.public boolean isAuthenticated()
true if valid tokens are available for the user.public void getTokens(android.net.Uri uri)
Checks if the Uri passed to this method is valid. We can avoid a function
uri - Required: The redirect Uri.public void handleCustomTabsCancelled()
public void unbindServiceConnection()
mCustomTabsServiceConnection