Search in sources :

Example 21 with SignInResult

use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.

the class AWSMobileClientPersistenceTest method testGetUserName.

@Test
public void testGetUserName() {
    signInAndVerifySignIn();
    assertNotNull(auth.getUsername());
    deleteAllEncryptionKeys();
    assertNull(auth.getUsername());
    try {
        final SignInResult signInResult = auth.signIn(username, PASSWORD, null);
        assertNotNull(signInResult);
        assertEquals(SignInState.DONE, signInResult.getSignInState());
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
    assertNotNull(auth.getUsername());
}
Also used : UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException) SignInResult(com.amazonaws.mobile.client.results.SignInResult) Test(org.junit.Test)

Example 22 with SignInResult

use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.

the class AWSMobileClientPersistenceTest method testGetIdentityId.

@Test
public void testGetIdentityId() {
    signInAndVerifySignIn();
    String identityId = auth.getIdentityId();
    assertNotNull(identityId);
    deleteAllEncryptionKeys();
    assertNull(auth.getIdentityId());
    try {
        final SignInResult signInResult = auth.signIn(username, PASSWORD, null);
        assertNotNull(signInResult);
        assertEquals(SignInState.DONE, signInResult.getSignInState());
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
    String identityIdAfterSecondSignIn = auth.getIdentityId();
    assertNotNull(identityIdAfterSecondSignIn);
    assertEquals(identityId, identityIdAfterSecondSignIn);
}
Also used : UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException) SignInResult(com.amazonaws.mobile.client.results.SignInResult) Test(org.junit.Test)

Example 23 with SignInResult

use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.

the class AWSMobileClientPersistenceTest method testGetUserAttributes.

@Test
public void testGetUserAttributes() throws Exception {
    signInAndVerifySignIn();
    Map<String, String> userAttributes = auth.getUserAttributes();
    assertNotNull(userAttributes);
    assertEquals(getPackageConfigure().getString("email"), userAttributes.get("email"));
    deleteAllEncryptionKeys();
    try {
        auth.getUserAttributes();
    } catch (Exception ex) {
        assertEquals("Operation requires a signed-in state", ex.getMessage());
    }
    try {
        final SignInResult signInResult = auth.signIn(username, PASSWORD, null);
        assertNotNull(signInResult);
        assertEquals(SignInState.DONE, signInResult.getSignInState());
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
    userAttributes = auth.getUserAttributes();
    assertNotNull(userAttributes);
    assertEquals(getPackageConfigure().getString("email"), userAttributes.get("email"));
}
Also used : UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException) SignInResult(com.amazonaws.mobile.client.results.SignInResult) Test(org.junit.Test)

Example 24 with SignInResult

use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.

the class AWSMobileClientPersistenceTest method testGetTokens.

// When the encryption keys are lost and retrieval of
// tokens from persistent store fails, calling getTokens()
// will throw an exception and the UserStateListener will
// be triggered the userState as SIGNED_OUT. Followed by a
// SignIn operation, getTokens() will retrieve
// the tokens successfully and trigger the userState as
// SIGNED_IN.
@Test
public void testGetTokens() throws Exception {
    signInAndVerifySignIn();
    final CountDownLatch stateNotificationLatch = new CountDownLatch(1);
    final AtomicReference<UserStateDetails> userState = new AtomicReference<UserStateDetails>();
    listener = new UserStateListener() {

        @Override
        public void onUserStateChanged(UserStateDetails details) {
            userState.set(details);
            stateNotificationLatch.countDown();
        }
    };
    auth.addUserStateListener(listener);
    deleteAllEncryptionKeys();
    try {
        auth.getTokens();
    } catch (Exception ex) {
        assertEquals("getTokens does not support retrieving tokens while signed-out", ex.getMessage());
    }
    stateNotificationLatch.await(10, TimeUnit.SECONDS);
    assertEquals(UserState.SIGNED_OUT, userState.get().getUserState());
    try {
        final SignInResult signInResult = auth.signIn(username, PASSWORD, null);
        assertNotNull(signInResult);
        assertEquals(SignInState.DONE, signInResult.getSignInState());
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
    Tokens tokens = auth.getTokens();
    verifyTokens(tokens);
    assertEquals(UserState.SIGNED_IN, userState.get().getUserState());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException) SignInResult(com.amazonaws.mobile.client.results.SignInResult) Tokens(com.amazonaws.mobile.client.results.Tokens) Test(org.junit.Test)

Example 25 with SignInResult

use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.

the class AWSMobileClientPersistenceWithRestartabilityTest method testIsSignedIn.

@Test
public void testIsSignedIn() {
    signInAndVerifySignIn();
    assertTrue(auth.isSignedIn());
    deleteAllEncryptionKeys();
    initializeAWSMobileClient(appContext, UserState.SIGNED_OUT);
    assertFalse(auth.isSignedIn());
    try {
        final SignInResult signInResult = auth.signIn(username, PASSWORD, null);
        assertNotNull(signInResult);
        assertEquals(SignInState.DONE, signInResult.getSignInState());
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
    assertTrue(auth.isSignedIn());
}
Also used : JSONException(org.json.JSONException) UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException) SignInResult(com.amazonaws.mobile.client.results.SignInResult) Test(org.junit.Test)

Aggregations

SignInResult (com.amazonaws.mobile.client.results.SignInResult)33 Test (org.junit.Test)21 UserNotConfirmedException (com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException)16 JSONException (org.json.JSONException)14 Tokens (com.amazonaws.mobile.client.results.Tokens)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 UserCodeDeliveryDetails (com.amazonaws.mobile.client.results.UserCodeDeliveryDetails)7 HashMap (java.util.HashMap)7 AuthSignInResult (com.amplifyframework.auth.result.AuthSignInResult)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)5 AWSCredentials (com.amazonaws.auth.AWSCredentials)4 ReturningRunnable (com.amazonaws.mobile.client.internal.ReturningRunnable)4 Token (com.amazonaws.mobile.client.results.Token)3 CognitoDevice (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice)3 CognitoUserSession (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession)3 AuthenticationContinuation (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation)3 AuthenticationDetails (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails)3 ChallengeContinuation (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation)3 MultiFactorAuthenticationContinuation (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation)3