3

I'm following these pages to use cognito on my mobile app https://docs.aws.amazon.com/aws-mobile/latest/developerguide/getting-started.html and https://aws.amazon.com/blogs/mobile/easy-sign-in-and-sign-up-ui-with-the-aws-mobile-sdk-for-android/

I have created the mobile hub and downloaded the json file but now it wants me to create a cognito user pool, but I already have one. How can I link the mobile hub with the existing user pool?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
casolorz
  • 8,486
  • 19
  • 93
  • 200

2 Answers2

4

AWS Mobile Hub does not currently provide a means to import your existing Cognito User Pool into the project, however, you can use whatever Cognito User Pool you like with the Mobile Hub-generated Cognito Identity Pool with a few easy steps. First, add a User Pool to the Mobile Hub project, so the project has Auth enabled. Then click on the Resources link and find your Cognito Identity Pool, and click the deep-link to the Cognito console. Now, click to Edit your Identity Pool. Under "Authentication Providers" you'll find settings for the Cognito User Pool; set those values based on your Cognito User Pool. Then, go back into the Mobile Hub console and when you download the configuration file for whatever app platform you want, just edit the resulting file to put in the correct Cognito User Pool settings.

For example, if you're using Android, in the Mobile Hub console, you'll click "Integrate" on the Android card, and "Download Config File." Then, you'd edit these lines in the "awsconfiguration.json" file.

"CognitoUserPool": {
  "Default": {
    "PoolId": "us-east-1_9rEQUqXYZ",
    "AppClientId": "gsdnilro5k0hillo8t6ojlxyz",
    "AppClientSecret": "pkqbqn8ulo08lghald06sjeib4mvbvpd6b0qork2h30n5klixyz",
    "Region": "us-east-1"
  }
},

...to use the appropriate values for your Cognito User Pool, and you should be good to go.

Note that these instructions should let you re-use the Cognito User Pool, but because the Cognito Identity Pool has changed, your user identity ID values will change.

We have had several customers request being able to re-use their Cognito User Pool and Cognito Identity Pool, so we are working on prioritizing those requests, but I can't say exactly when that functionality would be available.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Andrew C
  • 406
  • 2
  • 6
  • Thanks Andrew. Is there a better way for me to use Cognito with Facebook and Google from Android, iOS and web? Also, with this method you've provided, I should be able to use it for Google and Facebook with the same Mobile Hub? – casolorz Feb 06 '18 at 20:50
  • Facebook and Google sign-in work on all platforms (iOS, Android, web) with Cognito. For example, you can configure Facebook and Google sign-in in Mobile Hub's User Sign-in feature page and then go to the Resources link and download the sample app project and it will include UI for Facebook and Google sign-in and the resulting access tokens will be federated with Cognito identity pool. Alternatively, you can setup Facebook/Google directly in the Cognito console without Mobile Hub. – Andrew C Feb 07 '18 at 21:16
  • I thought I had to use Mobile Hub to use Cognito from Android/iOS. Am I wrong about that? – casolorz Feb 07 '18 at 21:20
  • You do not need to use AWS Mobile Hub to use Cognito from Android/iOS. However, Mobile Hub does simplify the configuration of your Cognito resources with your IAM roles and policies, as well as helping setup other resources and their policies. – Andrew C Feb 08 '18 at 22:57
  • Hi @AndrewC, I'm finding it hard to understand this solution. I created a user pool on the mobile hub but I want my user pool to use email as the username, and have the phone number be optional. I'm trying to change the user pool but I'm not sure of what you mean by `Then click on the Resources link and find your Cognito Identity Pool, and click the deep-link to the Cognito console.` – Daniel Ormeño Mar 21 '18 at 11:41
  • I'm using the awsmobile cli tool. – Daniel Ormeño Mar 21 '18 at 11:42
1

AWS now supports the feature you requested.

New AWS Mobile Hub feature: Add an existing user pool to your Mobile Hub project

user19906
  • 323
  • 4
  • 12