Search in sources :

Example 1 with CognitoUserPool

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

the class AppSyncClientUnitTest method testConfigMismatch_AmazonCognitoUserPools.

@Test(expected = RuntimeException.class)
public void testConfigMismatch_AmazonCognitoUserPools() {
    awsConfiguration.setConfiguration("ApiKey");
    APIKeyAuthProvider apiKeyAuthProvider = new BasicAPIKeyAuthProvider(awsConfiguration);
    awsConfiguration.setConfiguration("AmazonCognitoUserPools");
    CognitoUserPool cognitoUserPool = new CognitoUserPool(shadowContext, awsConfiguration);
    BasicCognitoUserPoolsAuthProvider basicCognitoUserPoolsAuthProvider = new BasicCognitoUserPoolsAuthProvider(cognitoUserPool);
    final AWSAppSyncClient awsAppSyncClient = AWSAppSyncClient.builder().context(shadowContext).awsConfiguration(awsConfiguration).apiKey(apiKeyAuthProvider).build();
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) BasicCognitoUserPoolsAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicCognitoUserPoolsAuthProvider) APIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.APIKeyAuthProvider) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) Test(org.junit.Test)

Example 2 with CognitoUserPool

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

the class AppSyncClientUnitTest method testAmazonCognitoUserPoolsAuthProvider.

@Test
public void testAmazonCognitoUserPoolsAuthProvider() {
    awsConfiguration.setConfiguration("AmazonCognitoUserPools");
    CognitoUserPool cognitoUserPool = new CognitoUserPool(shadowContext, awsConfiguration);
    BasicCognitoUserPoolsAuthProvider basicCognitoUserPoolsAuthProvider = new BasicCognitoUserPoolsAuthProvider(cognitoUserPool);
    final AWSAppSyncClient awsAppSyncClient = AWSAppSyncClient.builder().context(shadowContext).awsConfiguration(awsConfiguration).cognitoUserPoolsAuthProvider(basicCognitoUserPoolsAuthProvider).build();
    assertNotNull(awsAppSyncClient);
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) BasicCognitoUserPoolsAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicCognitoUserPoolsAuthProvider) Test(org.junit.Test)

Example 3 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class AWSMobileClientAuthFlowSettingTest method verifyScenario.

/**
 * Verify that the correct auth type (aka challenge name) is passed in based on the
 * auth flow type from the config file.
 * @param configAuthFlowType The auth flow type from the config.
 * @param expectedAuthType The auth type expected.
 * @param overridenAuthFlowType The authType passed to the API
 * @throws JSONException Not expected.
 * @throws InterruptedException Not expected.
 */
private void verifyScenario(String configAuthFlowType, String overridenAuthFlowType, String expectedAuthType) throws JSONException, InterruptedException {
    AuthenticationContinuation mockContinuation = setupMockContinuation();
    CognitoUserPool mockUserPool = setupMockUserPool(mockContinuation);
    initMobileClientAndWait(configAuthFlowType, mockUserPool);
    signinAndWait(overridenAuthFlowType);
    ArgumentCaptor<AuthenticationDetails> argumentCaptor = ArgumentCaptor.forClass(AuthenticationDetails.class);
    verify(mockContinuation).setAuthenticationDetails(argumentCaptor.capture());
    AuthenticationDetails actualAuthDetails = argumentCaptor.getValue();
    assertEquals(expectedAuthType, actualAuthDetails.getAuthenticationType());
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) AuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation) AuthenticationDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails)

Example 4 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class AWSMobileClientAuthFlowSettingTest method setupMockUserPool.

private CognitoUserPool setupMockUserPool(AuthenticationContinuation mockContinuation) {
    CognitoUserPool mockUserPool = mock(CognitoUserPool.class);
    CognitoUser mockUser = mock(CognitoUser.class);
    doAnswer(invocation -> {
        int indexOfHandler = 1;
        AuthenticationHandler handler = invocation.getArgument(indexOfHandler, AuthenticationHandler.class);
        handler.getAuthenticationDetails(mockContinuation, "FAKE_USER_ID");
        return null;
    }).when(mockUser).getSession(any(), any());
    when(mockUserPool.getUser(anyString())).thenReturn(mockUser);
    return mockUserPool;
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser)

Example 5 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class SignUpActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_up);
    signUpView = (SignUpView) findViewById(R.id.signup_view);
    Context appContext = getApplicationContext();
    mUserPool = new CognitoUserPool(appContext, new AWSConfiguration(appContext));
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
Also used : Context(android.content.Context) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) InputMethodManager(android.view.inputmethod.InputMethodManager) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration)

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