This tutorial will focus on using Cognito with the AWS Javascript SDK for Node.js along with the Node Passport module to simplify token creation. This could be used with apps that access files on a server or 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:
Assumptions. You know the following:
1. How to set up Node on an EC2 instance.
2. Can configure firewall settings on EC2.
3. Experienced with Node and Express.
The complete code for the tutorial is at GitHub.
Register a Facebook App
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 Add Platform
Select Website
Site URL enter your site's Facebook callback page: http://yoursite.com/auth/facebook/callback
App Domains enter your site domain: http://yoursite.com
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.
Create a Cognito Pool
Now that we have a Facebook App registered we need to create a Cognito pool that will be linked to the Facebook app.
Go to the Cognito start page and click Get Started Now
Step 1:
Give your app a name in Identity Pool Name.
Paste your Facebook App ID.
Leave Enable Access to Unauthenticated Identities unchecked.
Click Create Pool
Step 2:
An IAM role has been automatically created for you. Click Update Roles
Step 3:
Example code for native mobile apps has been created for you which is useless for us with javascript so just click Done.
Finished! You have created a Cognito pool and are viewing its dashboard.
In part 2 we will create a Node.JS application that connects to Cognito ID.
See you in Part 2!
No comments:
Post a Comment