Search in sources :

Example 1 with AWSCognitoAuthSignOutOptions

use of com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignOutOptions in project amplify-android by aws-amplify.

the class AWSCognitoAuthPlugin method signOutLocally.

private void signOutLocally(@NonNull AuthSignOutOptions options, @NonNull Action onSuccess, @NonNull Consumer<AuthException> onError) {
    SignOutOptions.Builder signOutOptionsBuilder = SignOutOptions.builder().signOutGlobally(false).invalidateTokens(true);
    if (options instanceof AWSCognitoAuthSignOutOptions) {
        signOutOptionsBuilder.browserPackage(((AWSCognitoAuthSignOutOptions) options).getBrowserPackage());
    }
    awsMobileClient.signOut(signOutOptionsBuilder.build(), new Callback<Void>() {

        @Override
        public void onResult(Void result) {
            onSuccess.call();
        }

        @Override
        public void onError(Exception error) {
            if (error != null && error.getMessage() != null && error.getMessage().contains("signed-out")) {
                onError.accept(new AuthException("Failed to sign out since Auth is already signed out", "No need to sign out - you already are!"));
            } else if (error instanceof AuthNavigationException) {
                // User cancelled the sign-out screen.
                onError.accept(new AuthException.UserCancelledException("The user cancelled the sign-out attempt.", error, "To recover, catch this error, and retry sign-out."));
            } else {
                onError.accept(new AuthException("Failed to sign out", error, "See attached exception for more details"));
            }
        }
    });
}
Also used : SignOutOptions(com.amazonaws.mobile.client.SignOutOptions) AuthSignOutOptions(com.amplifyframework.auth.options.AuthSignOutOptions) AWSCognitoAuthSignOutOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignOutOptions) AWSCognitoAuthSignOutOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignOutOptions) AuthException(com.amplifyframework.auth.AuthException) AuthException(com.amplifyframework.auth.AuthException) JSONException(org.json.JSONException) AmplifyException(com.amplifyframework.AmplifyException) NotAuthorizedException(com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException) AuthNavigationException(com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException) AuthNavigationException(com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException)

Aggregations

SignOutOptions (com.amazonaws.mobile.client.SignOutOptions)1 AuthNavigationException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException)1 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)1 AmplifyException (com.amplifyframework.AmplifyException)1 AuthException (com.amplifyframework.auth.AuthException)1 AWSCognitoAuthSignOutOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignOutOptions)1 AuthSignOutOptions (com.amplifyframework.auth.options.AuthSignOutOptions)1 JSONException (org.json.JSONException)1