Skip to content

Commit

Permalink
Update federatedSignIn to immediately contact service; refresh Google…
Browse files Browse the repository at this point in the history
…/Facebook from drop-in UI

Updated `federatedSignIn()` method to contact the service immediately to validate tokens. The `signIn()` method will also attempt to federated immediately when applicable. See [issue aws-amplify#800](aws-amplify#800)
Fix Google or Facebook refresh when using the drop-in UI. See [issue aws-amplify#809](aws-amplify#809), [issue aws-amplify#700](aws-amplify#700)
Annotated methods that are designed to be called from UI thread or from a background thread with @anythread and @workerthread, respectively.
  • Loading branch information
minbi committed Apr 2, 2019
1 parent b634242 commit bd81c97
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 51 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## [Release 2.12.7](https://github.com/aws/aws-sdk-android/releases/tag/release_v2.12.7)

### Enhancements

* **AWS Mobile Client**
* Updated `federatedSignIn()` method to contact the service immediately to validate tokens. The `signIn()` method will also attempt to federated immediately when applicable. See [issue #800](https://github.com/aws-amplify/aws-sdk-android/issues/800)
* Fix Google or Facebook refresh when using the drop-in UI. See [issue #809](https://github.com/aws-amplify/aws-sdk-android/issues/809), [issue #700](https://github.com/aws-amplify/aws-sdk-android/issues/700)
* Annotated methods that are designed to be called from UI thread or from a background thread with @AnyThread and @WorkerThread, respectively.

### Bug Fixes

* **AWS Core**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public class GoogleSignInProvider implements SignInProvider, SignInPermissionsHa

/**
* Constructor. Builds the Google Api Client.
* @param context context.
* @param configuration the AWS Configuration.
* @param activityContext context.
* @param awsConfig the AWS Configuration.
*/
@Override
public void initialize(@NonNull final Context activityContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProvider;
import com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient;
import com.amazonaws.services.cognitoidentityprovider.model.AdminConfirmSignUpRequest;
import com.amazonaws.services.cognitoidentityprovider.model.AdminDeleteUserRequest;
import com.amazonaws.services.cognitoidentityprovider.model.AdminGetDeviceRequest;
import com.amazonaws.services.cognitoidentityprovider.model.AdminGetDeviceResult;
import com.amazonaws.services.cognitoidentityprovider.model.AttributeType;
Expand All @@ -34,6 +35,7 @@
import com.amazonaws.services.cognitoidentityprovider.model.ListUsersRequest;
import com.amazonaws.services.cognitoidentityprovider.model.ListUsersResult;
import com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException;
import com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException;
import com.amazonaws.services.cognitoidentityprovider.model.UserType;
import com.amazonaws.services.cognitoidentityprovider.model.UsernameExistsException;

Expand Down Expand Up @@ -137,16 +139,29 @@ public static void deleteAllUsers(final String userpoolId) {
// This user is saved to test the identity id permanence
continue;
}
try {
Log.d(TAG, "deleteAllUsers: " + user.getUsername());
AWSMobileClient.getInstance().signIn(user.getUsername(), PASSWORD, null);
DeleteUserRequest deleteUserRequest = new DeleteUserRequest()
.withAccessToken(AWSMobileClient.getInstance().getTokens().getAccessToken().getTokenString());
getUserpoolLL().deleteUser(deleteUserRequest);
AWSMobileClient.getInstance().signOut();
} catch (Exception e) {
Log.e(TAG, "deleteAllUsers: Some error trying to delete user", e);
}
boolean retryConfirmSignUp = false;
do {
try {
Log.d(TAG, "deleteAllUsers: " + user.getUsername());
getUserpoolLL().adminDeleteUser(new AdminDeleteUserRequest().withUsername(user.getUsername()).withUserPoolId(userpoolId));
} catch (UserNotConfirmedException e) {
if (!retryConfirmSignUp) {
AdminConfirmSignUpRequest adminConfirmSignUpRequest = new AdminConfirmSignUpRequest();
adminConfirmSignUpRequest.withUsername(user.getUsername()).withUserPoolId(userpoolId);
getUserpoolLL().adminConfirmSignUp(adminConfirmSignUpRequest);
retryConfirmSignUp = true;
try {
Thread.sleep(10);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
} else {
retryConfirmSignUp = false;
}
} catch (Exception e) {
Log.e(TAG, "deleteAllUsers: Some error trying to delete user", e);
}
} while (retryConfirmSignUp);
}
} while (listUsersResult.getPaginationToken() != null);
}
Expand Down Expand Up @@ -428,8 +443,12 @@ public void testSignInWrongPassword() throws Exception {
}

@Test
public void testFederate() {

public void testFederatedSignInFail() {
try {
auth.federatedSignIn(IdentityProvider.GOOGLE.toString(), "fakeToken");
} catch (Exception e) {
assertEquals("Error in federating the token.", e.getMessage());
}
}

// Changing a password tends to have a rate limit that exceeds test timeout
Expand Down
Loading

0 comments on commit bd81c97

Please sign in to comment.