Paul Coady
Melbourne, Australia
Amazon Web Services, Node, Angular, Famo.us, Cordova/Phonegap
Please go to our Blogger site at blog.backspace.academy This site will no longer be updated.
Using Cognito with PhoneGap/Cordova
The potential for really powerful mobile applications is huge when Cognito is used to combine the power of AWS with your PhoneGap/Cordova application. It is also a great low cost alternative to Parse.com when used for storing user information.
This tutorial will focus on using Cognito with the AWS Javascript SDK for Browser along with the excellent OpenFB library developed by Christophe Coenraets to simplify token creation. The sample app will be created for the Adobe PhoneGap Build process. This could be used with apps that access files on an S3 bucket and also require user information to be stored. I have chosen Facebook as the identity provider but a similar process applies for Amazon and Google. I would recommend only using one identity provider for your app so that your users don't produce multiple Cognito key stores.
With the release of v2.0.14 of the AWS Javascript SDK, a new object CognitoIdentityCredentials has greatly simplified the CognitoID credentials process by removing the need to create STS tokens and temporary IAM credentials. The simplified process to create a Cognito session is as follows:
Register a Facebook App
This process is different to that used with NodeJS because the app will be running from the device local domain.
Go to developers.facebook.com and select Apps - Create a New App
Record your App ID and App Secret somewhere safe, we will need it later.
Click on Settings then click on Advanced (do not fill in app domain details or add platform).
Select Native or Desktop app.
Add https://www.facebook.com/connect/login_success.html as the Valid OAuth redirect URI.
Enter your contact email and Save Changes
Next select Status and Review
Toggle Yes for Do you want to make this app and all its live features available to the general public?
Now that we have registered our new app with Facebook, we will tell Cognito all about it on the next page.
Like this tutorial? Please click the share buttons to tell others.
Next - Create a Cognito Pool