Search in sources :

Example 56 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-mobile-appsync-sdk-android by awslabs.

the class CustomCognitoUserPool method setup.

@NonNull
public static String setup() {
    // Sign in the user.
    Await.result((Await.ResultErrorEmitter<SignInResult, RuntimeException>) (onResult, onError) -> {
        DelegatingMobileClientCallback<SignInResult> callback = DelegatingMobileClientCallback.to(onResult, exception -> onError.accept(new RuntimeException(exception)));
        TestAWSMobileClient.instance(getTargetContext()).signIn("appsync-multi-auth-test-user", "P@ssw0rd!", null, callback);
    });
    // Build a custom cognito user pool.
    AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
    awsConfiguration.setConfiguration("Custom");
    CognitoUserPool cognitoUserPool = new CognitoUserPool(getTargetContext(), awsConfiguration);
    // Get the ID token for this user.
    return Await.result((onResult, onError) -> cognitoUserPool.getUser("appsync-multi-auth-test-user").getSession(new AuthenticationHandler() {

        @Override
        public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice) {
            onResult.accept(userSession.getIdToken().getJWTToken());
        }

        @Override
        public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId) {
            Log.d(TAG, "Sending password.");
            authenticationContinuation.setAuthenticationDetails(new AuthenticationDetails("appsync-multi-auth-test-user", "P@ssw0rd!", null));
            authenticationContinuation.continueTask();
        }

        @Override
        public void getMFACode(MultiFactorAuthenticationContinuation continuation) {
        }

        @Override
        public void authenticationChallenge(ChallengeContinuation continuation) {
        }

        @Override
        public void onFailure(Exception exception) {
            onError.accept(new RuntimeException(exception));
        }
    }));
}
Also used : InstrumentationRegistry.getTargetContext(androidx.test.InstrumentationRegistry.getTargetContext) NonNull(androidx.annotation.NonNull) CognitoUserSession(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession) SignInResult(com.amazonaws.mobile.client.results.SignInResult) Await(com.amazonaws.mobileconnectors.appsync.util.Await) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) AuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) AuthenticationDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails) ChallengeContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) Log(android.util.Log) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) SignInResult(com.amazonaws.mobile.client.results.SignInResult) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) AuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) ChallengeContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) CognitoUserSession(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession) Await(com.amazonaws.mobileconnectors.appsync.util.Await) AuthenticationDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails) NonNull(androidx.annotation.NonNull)

Aggregations

CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)56 Test (org.junit.Test)41 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)28 ArgumentCaptor (org.mockito.ArgumentCaptor)11 SharedPreferences (android.content.SharedPreferences)9 CognitoUser (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser)9 GetUserRequest (com.amazonaws.services.cognitoidentityprovider.model.GetUserRequest)8 ResourceNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)8 CognitoUserAttributes (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes)7 SignUpResult (com.amazonaws.services.cognitoidentityprovider.model.SignUpResult)7 Before (org.junit.Before)7 CognitoUserCodeDeliveryDetails (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails)6 CognitoUserDetails (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserDetails)6 GetDetailsHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler)6 SignUpHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler)6 UpdateAttributesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler)6 SignUpRequest (com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest)6 UnexpectedLambdaException (com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException)6 UpdateUserAttributesRequest (com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesRequest)6 ClientConfiguration (com.amazonaws.ClientConfiguration)4