use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.
the class OAuth2Utils method _confirmSignIn.
private Runnable _confirmSignIn(final String signInChallengeResponse, final Map<String, String> clientMetadata, final Map<String, String> userAttributes, final Callback<SignInResult> callback) {
return new Runnable() {
@Override
public void run() {
if (signInState == null) {
callback.onError(new IllegalStateException("Cannot call confirmSignIn(String, Callback) " + "without initiating sign-in. This call is used for SMS_MFA and NEW_PASSWORD_REQUIRED " + "sign-in state."));
return;
}
final CognitoIdentityProviderContinuation detectedContinuation;
switch(signInState) {
case SMS_MFA:
signInMfaContinuation.setMfaCode(signInChallengeResponse);
signInMfaContinuation.setClientMetaData(clientMetadata);
detectedContinuation = signInMfaContinuation;
signInCallback = new InternalCallback<SignInResult>(callback);
break;
case NEW_PASSWORD_REQUIRED:
((NewPasswordContinuation) signInChallengeContinuation).setPassword(signInChallengeResponse);
signInChallengeContinuation.setClientMetaData(clientMetadata);
for (final String key : userAttributes.keySet()) {
signInChallengeContinuation.setChallengeResponse(CHALLENGE_RESPONSE_USER_ATTRIBUTES_PREFIX_KEY + key, userAttributes.get(key));
}
detectedContinuation = signInChallengeContinuation;
signInCallback = new InternalCallback<SignInResult>(callback);
break;
case CUSTOM_CHALLENGE:
signInChallengeContinuation.setChallengeResponse("ANSWER", signInChallengeResponse);
detectedContinuation = signInChallengeContinuation;
signInCallback = new InternalCallback<SignInResult>(callback);
if (clientMetadata != null) {
signInChallengeContinuation.setClientMetaData(clientMetadata);
}
break;
case DONE:
callback.onError(new IllegalStateException("confirmSignIn called after signIn has succeeded"));
return;
default:
callback.onError(new IllegalStateException("confirmSignIn called on unsupported operation, " + "please file a feature request"));
return;
}
if (detectedContinuation != null) {
detectedContinuation.continueTask();
}
}
};
}
use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.
the class AWSMobileClientPersistenceTest method testIsSignedIn.
@Test
public void testIsSignedIn() {
signInAndVerifySignIn();
assertTrue(auth.isSignedIn());
deleteAllEncryptionKeys();
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());
}
use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.
the class AWSMobileClientPersistenceWithRestartabilityTest 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();
initializeAWSMobileClient(appContext, UserState.SIGNED_OUT);
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"));
}
use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.
the class AWSMobileClientPersistenceWithRestartabilityTest 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());
}
use of com.amazonaws.mobile.client.results.SignInResult in project aws-sdk-android by aws-amplify.
the class AWSMobileClientPersistenceWithRestartabilityTest method signInAndVerifySignIn.
private void signInAndVerifySignIn() {
try {
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);
auth.removeUserStateListener(listener);
stateNotificationLatch.countDown();
}
};
auth.addUserStateListener(listener);
final SignInResult signInResult = auth.signIn(username, PASSWORD, null);
assertEquals("Cannot support MFA in tests", SignInState.DONE, signInResult.getSignInState());
assertTrue("isSignedIn is true", auth.isSignedIn());
assertEquals(username, auth.getUsername());
// Check credentials are available
final AWSCredentials credentials = auth.getCredentials();
assertNotNull("Credentials are null", credentials);
assertNotNull("Access key is null", credentials.getAWSAccessKeyId());
assertNotNull("Secret key is null", credentials.getAWSSecretKey());
Tokens tokens = auth.getTokens();
assertNotNull(tokens);
Token accessToken = tokens.getAccessToken();
assertNotNull(accessToken);
assertTrue("Access token should not be expired", accessToken.getExpiration().after(new Date()));
Token idToken = tokens.getIdToken();
assertNotNull(idToken);
assertTrue("Id token should not be expired", idToken.getExpiration().after(new Date()));
Token refreshToken = tokens.getRefreshToken();
assertNotNull(refreshToken);
// Check one attribute
final Map<String, String> userAttributes = auth.getUserAttributes();
assertEquals(getPackageConfigure().getString("email"), userAttributes.get("email"));
stateNotificationLatch.await(5, TimeUnit.SECONDS);
UserStateDetails userStateDetails = userState.get();
assertEquals(userStateDetails.getUserState(), UserState.SIGNED_IN);
Map<String, String> details = userStateDetails.getDetails();
assertNotEquals(getPackageConfigure().getString("identity_id"), details.toString());
} catch (Exception ex) {
fail(ex.getMessage());
}
}
Aggregations