AWS Cognito Setup for User Authentication
Tags: aws, cognito, node, express
Published: 2023-06-07 12:55:06

## AWS Cognito Overview

Amazon Cognito lets you add user sign-up, sign-in, and access control to your web and mobile apps quickly and easily. Amazon Cognito scales to millions of users and supports sign-in with social identity providers, such as Facebook, Google, and Amazon, and enterprise identity providers via SAML 2.0.

Let’s understand what is AWS Cognito User Pool and AWS Cognito Federal Identity

- AWS Cognito User Pool
- AWS Cognito Federated Identities

### 1. AWS Cognito User Pool

A User Pool is the user directory that you can configure for your web and mobile apps. A User Pool securely stores your users’ profile attributes. You can create and manage a User Pool using the AWS console, AWS CLI, or AWS SDK.

#### Create Cognito User Pool

- Sign in/up to your AWS account from the Services drop-down menu select Cognito then you will see the following screen. Click to the User Pools Button in the left sidebar.

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fuserpool01.22121787.png&w=1920&q=75)

<br />

- Click on the Create user pool button.

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fuserpool02.b164683d.png&w=1920&q=75)

<br />

- Select Authentication Providers Type

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fuserpool03.9588da63.png&w=1920&q=75)

<br />

- Select Password policy mode and Multi-factor authentication type

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fuserpool04.561f458c.png&w=1920&q=75)

<br />

- Select MFA methods(Authenticator apps or SMS message)

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fuserpool05.0ccb3013.png&w=1920&q=75)

<br />

- Choose the attributes, and click next button.

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fuserpool06.1a49a4c5.png&w=1920&q=75)

<br />

- Select Email provider, and click next button.

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fuserpool07.6c26803a.png&w=1920&q=75)

<br />

- Enter User pool name.

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fuserpool08.20d8594e.png&w=1920&q=75)

<br />

- Check Use the Cognito Hosted UI, enter a domain prefix.

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fuserpool09.ba3dd2e6.png&w=1920&q=75)

<br />

- Enter a friendly name for yhour app client, and enter a callback URLs.

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fuserpool10.d6223557.png&w=1920&q=75)

<br />

- You will see the user pool has been created as shown below in the screenshot.

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fuserpool11.d87dd648.png&w=1920&q=75)

  <br />

- Finally you can check the all of authentication work flow in the Cognito Hosted UI.

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fuserpool12.d140dde0.png&w=1920&q=75)

  <br />

### 2. AWS Cognito Federated Identities

Identity pools are the containers that Cognito Identity uses to keep your apps’ federated identities organized. Identity Pool associates federated identities from social identity providers with a unique user-specific identifier. Identity Pools do not store any user profiles. An identity pool can be associated with one or many apps. If you use two different identity pools for two apps then the same end user will have a different unique identifier in each Identity Pool.

#### Create Cognito Federated Identities

- Click a Create new identity pool button as shown in the below screenshot.

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ffederated01.9a668383.png&w=1920&q=75)

<br />

- Enter the User Pool Id and App client id as shown in the below screenshot.

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ffederated02.16b5e1c5.png&w=1920&q=75)

<br />

- Enter the User Pool Id and App client id as shown in the below screenshot.

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ffederated02.16b5e1c5.png&w=1920&q=75)

<br />

- Then you can get the Identity pool Id as shown in the below screenshot

  ![Cognito User Pool](https://chrisw.vercel.app/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ffederated03.bb471d04.png&w=1920&q=75)

<br />

I just done with AWS Cognito User Pool, Cognito Federated Identities setup.
In the [next post](https://dev.to/itwebtiger/aws-cognito-sign-up-with-nodejs-4202), we will discuss how you're going to integrate Cognito with a Node.js & Express.js app.

#### References
https://chrisw.vercel.app/projects/node/cognito/started