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"));
}
}
});
}
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.");
}
}
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"));
}
}
});
}
Aggregations