Search in sources :

Example 1 with AWSCognitoAuthSignInOptions

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

the class AWSCognitoAuthPlugin method signIn.

@Override
public void signIn(@Nullable String username, @Nullable String password, @NonNull AuthSignInOptions options, @NonNull final Consumer<AuthSignInResult> onSuccess, @NonNull final Consumer<AuthException> onException) {
    final Map<String, String> metadata = new HashMap<>();
    AuthFlowType authFlowType = null;
    if (options instanceof AWSCognitoAuthSignInOptions) {
        metadata.putAll(((AWSCognitoAuthSignInOptions) options).getMetadata());
        authFlowType = ((AWSCognitoAuthSignInOptions) options).getAuthFlowType();
    }
    com.amazonaws.services.cognitoidentityprovider.model.AuthFlowType sdkAuthFlowType = null;
    if (authFlowType != null) {
        sdkAuthFlowType = com.amazonaws.services.cognitoidentityprovider.model.AuthFlowType.valueOf(authFlowType.name());
    }
    awsMobileClient.signIn(username, password, metadata, Collections.emptyMap(), sdkAuthFlowType, new Callback<SignInResult>() {

        @Override
        public void onResult(SignInResult result) {
            try {
                AuthSignInResult newResult = convertSignInResult(result);
                fetchAndSetUserId(() -> onSuccess.accept(newResult));
            } catch (AuthException exception) {
                onException.accept(exception);
            }
        }

        @Override
        public void onError(Exception error) {
            onException.accept(CognitoAuthExceptionConverter.lookup(error, "Sign in failed"));
        }
    });
}
Also used : AWSCognitoAuthSignInOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignInOptions) HashMap(java.util.HashMap) 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) SignInResult(com.amazonaws.mobile.client.results.SignInResult) AuthSignInResult(com.amplifyframework.auth.result.AuthSignInResult) AuthFlowType(com.amplifyframework.auth.cognito.options.AuthFlowType) AuthSignInResult(com.amplifyframework.auth.result.AuthSignInResult)

Aggregations

SignInResult (com.amazonaws.mobile.client.results.SignInResult)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 AWSCognitoAuthSignInOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignInOptions)1 AuthFlowType (com.amplifyframework.auth.cognito.options.AuthFlowType)1 AuthSignInResult (com.amplifyframework.auth.result.AuthSignInResult)1 HashMap (java.util.HashMap)1 JSONException (org.json.JSONException)1