Search in sources :

Example 1 with AuthNavigationException

use of com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException 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)

Example 2 with AuthNavigationException

use of com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException in project aws-sdk-android by aws-amplify.

the class AuthClient method endSession.

/**
 * Ends current browser session.
 * @param browserPackage browser package to launch sign-out endpoint from.
 * @throws AuthClientException if sign-out redirect fails to resolve.
 */
private void endSession(final String browserPackage) throws AuthClientException {
    boolean redirectReceived;
    try {
        cookiesCleared = new CountDownLatch(1);
        launchSignOut(pool.getSignOutRedirectUri(), browserPackage);
        if (!isRedirectActivityDeclared()) {
            cookiesCleared.countDown();
        }
        redirectReceived = cookiesCleared.await(REDIRECT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        throw new AuthNavigationException("User cancelled sign-out.");
    }
    if (!redirectReceived) {
        throw new AuthServiceException("Timed out while waiting for sign-out redirect response.");
    }
}
Also used : AuthServiceException(com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthServiceException) CountDownLatch(java.util.concurrent.CountDownLatch) AuthNavigationException(com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException)

Example 3 with AuthNavigationException

use of com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException in project amplify-android by aws-amplify.

the class AWSCognitoAuthPlugin method signInWithWebUIHelper.

private void signInWithWebUIHelper(@Nullable AuthProvider authProvider, @NonNull Activity callingActivity, @NonNull AuthWebUISignInOptions options, @NonNull Consumer<AuthSignInResult> onSuccess, @NonNull Consumer<AuthException> onException) {
    HostedUIOptions.Builder optionsBuilder = HostedUIOptions.builder();
    SignInUIOptions.Builder signInUIOptionsBuilder = SignInUIOptions.builder();
    if (options != null) {
        if (options.getScopes() != null) {
            optionsBuilder.scopes(options.getScopes().toArray(new String[options.getScopes().size()]));
        }
        if (!options.getSignInQueryParameters().isEmpty()) {
            optionsBuilder.signInQueryParameters(options.getSignInQueryParameters());
        }
        if (!options.getSignOutQueryParameters().isEmpty()) {
            optionsBuilder.signOutQueryParameters(options.getSignOutQueryParameters());
        }
        if (!options.getTokenQueryParameters().isEmpty()) {
            optionsBuilder.tokenQueryParameters(options.getTokenQueryParameters());
        }
        if (options instanceof AWSCognitoAuthWebUISignInOptions) {
            AWSCognitoAuthWebUISignInOptions cognitoOptions = (AWSCognitoAuthWebUISignInOptions) options;
            optionsBuilder.idpIdentifier(cognitoOptions.getIdpIdentifier()).federationProviderName(cognitoOptions.getFederationProviderName());
            signInUIOptionsBuilder.browserPackage(cognitoOptions.getBrowserPackage());
        }
        if (authProvider != null) {
            optionsBuilder.identityProvider(AuthProviderConverter.getIdentityProvider(authProvider));
        }
    }
    SignInUIOptions signInUIOptions = signInUIOptionsBuilder.hostedUIOptions(optionsBuilder.build()).build();
    awsMobileClient.showSignIn(callingActivity, signInUIOptions, new Callback<UserStateDetails>() {

        @Override
        public void onResult(UserStateDetails details) {
            fetchAndSetUserId(() -> onSuccess.accept(new AuthSignInResult(UserState.SIGNED_IN.equals(details.getUserState()), new AuthNextSignInStep(AuthSignInStep.DONE, details.getDetails(), null))));
        }

        @Override
        public void onError(Exception error) {
            if (error instanceof AuthNavigationException) {
                onException.accept(new AuthException.UserCancelledException("The user cancelled the sign-in attempt, so it did not complete.", error, "To recover: catch this error, and show the sign-in screen again."));
            } else {
                onException.accept(new AuthException("Sign-in with web UI failed", error, "See attached exception for more details"));
            }
        }
    });
}
Also used : AuthException(com.amplifyframework.auth.AuthException) AuthNextSignInStep(com.amplifyframework.auth.result.step.AuthNextSignInStep) UserStateDetails(com.amazonaws.mobile.client.UserStateDetails) 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) HostedUIOptions(com.amazonaws.mobile.client.HostedUIOptions) SignInUIOptions(com.amazonaws.mobile.client.SignInUIOptions) AWSCognitoAuthWebUISignInOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthWebUISignInOptions) AuthSignInResult(com.amplifyframework.auth.result.AuthSignInResult)

Aggregations

AuthNavigationException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException)3 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)2 AmplifyException (com.amplifyframework.AmplifyException)2 AuthException (com.amplifyframework.auth.AuthException)2 JSONException (org.json.JSONException)2 HostedUIOptions (com.amazonaws.mobile.client.HostedUIOptions)1 SignInUIOptions (com.amazonaws.mobile.client.SignInUIOptions)1 SignOutOptions (com.amazonaws.mobile.client.SignOutOptions)1 UserStateDetails (com.amazonaws.mobile.client.UserStateDetails)1 AuthServiceException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthServiceException)1 AWSCognitoAuthSignOutOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignOutOptions)1 AWSCognitoAuthWebUISignInOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthWebUISignInOptions)1 AuthSignOutOptions (com.amplifyframework.auth.options.AuthSignOutOptions)1 AuthSignInResult (com.amplifyframework.auth.result.AuthSignInResult)1 AuthNextSignInStep (com.amplifyframework.auth.result.step.AuthNextSignInStep)1 CountDownLatch (java.util.concurrent.CountDownLatch)1