Voiced by Amazon Polly |
1. Introduction
AWS Cognito offers two essential components for managing user authentication and access to AWS resources: User Pools and Identity Pools. User Pools serve as a user directory system, facilitating user registration, authentication, and account recovery within your application. User Pools support various authentication methods, including traditional username/password, OAuth 2.0, and multi-factor authentication (MFA). Upon successful authentication, User Pools generate JSON Web Tokens (JWTs), enabling secure user identification and session management within your application.
Identity Pools, also known as Cognito Identity Pools, play a crucial role in providing temporary AWS credentials to access AWS resources on behalf of your users. Identity Pools issue temporary AWS credentials as a bridge between authenticated users and AWS services, granting access to specific AWS resources based on defined IAM roles. They support both authenticated and unauthenticated (guest) access, allowing fine-grained control over permissions for different user types. Integration with various identity providers, including User Pools, social identity providers, and custom authentication systems, is possible with Identity Pools. Leveraging Identity Pools ensures secure interaction between your application and AWS services, such as S3, DynamoDB, and API Gateway, with access levels tailored to users’ roles and permissions.
Customized Cloud Solutions to Drive your Business Success
- Cloud Migration
- Devops
- AIML & IoT
2. Create a Cognito User Pool
- Sign in to AWS Console: Log in to your AWS account via the AWS Management Console.
- Navigate to AWS Cognito: Access the Amazon Cognito service either by using the search bar in the AWS Console.
- Create a User Pool:
- Click on “User Pools” followed by “Create a user pool”.
- In “Provider type,” Select “Cognito User Pool”. In Cognito user pool sign-in options, choose “Username and Email.”
- In the password policy, keep the Default setting. In MFA, you can select No MFA and keep the rest of the Default.
- Enter a name for your user pool, enable the “Use the Cognito Hosted UI,” and configure the domain (either use the Cognito domain or custom domain) as shown below.
- Adjust various settings such as user attributes, policies, and verification methods as needed.
- Create a New App Client:
- Click on the “Add an app client” button.
- Provide a name for your app client in the “App client name” field.
- Optionally, you can uncheck the “Generate client secret” box if you don’t need a client secret for your app. Note that certain OAuth flows require a client secret.
- Configure App Client Settings: You can configure various settings for your app client, such as OAuth 2.0 settings, allowed OAuth flows, callback URLs, and more. Ensure these settings align with the requirements of your application.
- Review and create a “User Pool”. Grab the User Pool ID and Client ID; we will need it further to generate a token.
3. Create an Identity Pool
- Return to the Amazon Cognito dashboard and select “Identity Pools.”
- Under “Authentication providers,” In ” Authenticated identity sources,” choose Cognito User Pool.
- Set up IAM Roles:
- Define IAM roles to specify the permissions for accessing AWS services.
- Opt to create new roles and grant Cognito the necessary permissions. Adjust permissions as required. For example, If you want the users to access S3, you can add the S3 policy in the Role attached for the Authenticated Role.
- Integrate the User Pool with the Identity Pool(Connect identity providers)
- Specify the user pool previously created and select the App Client previously created in the User Pool
- Review the setting and create an Identity Pool. Grab the Identity Pool ID. You will need it in further steps.
- Add the user to the Cognito User Pool by Signing Up.
4. Generate an id-token
- Obtain Your Cognito User Pool Information: Before proceeding, ensure you have the following information:
- Cognito User Pool ID
- Client ID of your Cognito App Client
- Username and password of a user registered in the Cognito User Pool
- Configure Postman: If you haven’t already, download and install Postman from https://www.postman.com/downloads/.
- Create a New Request: Open Postman and create a new request by clicking on the “New” button.
- In Authorization, Select the type OAuth2.0. Configure the Callback URL, Auth URL, Access Token URL, Client ID, and Client secret. Click on Get New Access Token. Enter the username and password of the Cognito user-created
- Grab the id_token from the Pop-up and copy it in Notepad.
5. Generate Temporary credentials with the Cognito Identity Pool.
Cognito Identity Pools issue temporary AWS credentials to authenticate users of your application. These credentials are obtained following user authentication with a supported identity provider, like Cognito User Pools or social identity providers. They grant access to AWS services for a limited time and are associated with specific permissions defined by IAM roles within the Identity Pool.
- Now, to generate the Temporary Credentials, we need to compose a JSON file Consisting of the required headers, such as AccountId, IdentityPoolId, and Logins, to generate The Syntax for the same is shown below.
{
"AccountId": "string",
"IdentityPoolId": "string",
"Logins": {
"string" : "string"
}
}
-
- Execute the following command by giving the JSON file as input.
$ aws cognito-identity get-id --cli-input-json file://getid.json
You should receive a Following Output
- Generate the temporary credentials using GetCredentialsForIdentity
- To generate credentials, create a JSON file using the IdentityId generated by the previous Step.
{
"IdentityId": "string",
"Logins": {
"string" : "string"
}
}
-
- Now execute the Following Command by passing the json file as input ss shown Below.
$ aws cognito-identity get-credentials-for-identity --cli-input-json file://get_cred.jsonYou will receive the following Output.
6. Testing Temporary credentials generated by Identity ID using Postman
- Pass the AccessKeyID, SecretKey, and SessionToken in Postman
You should be able to List the Objects from S3 Bucket as an Identity Provider Authenticated Role has S3 Policy (Permissions).
Output:
Conclusion
In summary, AWS Cognito User Pools handle user authentication within your application, issuing JWTs upon successful authentication, while AWS Cognito Identity Pools facilitate secure access to AWS resources by providing temporary credentials to authenticated users, subject to predefined IAM roles and permissions. This combined authentication and authorization process ensures seamless and secure user interactions with your application and AWS services.
Reference
https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html
Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.
- Cloud Training
- Customized Training
- Experiential Learning
About CloudThat
CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.
CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training Partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, AWS GenAI Competency Partner, Amazon QuickSight Service Delivery Partner, Amazon EKS Service Delivery Partner, AWS Microsoft Workload Partners, Amazon EC2 Service Delivery Partner, Amazon ECS Service Delivery Partner, AWS Glue Service Delivery Partner, Amazon Redshift Service Delivery Partner, AWS Control Tower Service Delivery Partner, AWS WAF Service Delivery Partner, Amazon CloudFront Service Delivery Partner, Amazon OpenSearch Service Delivery Partner, AWS DMS Service Delivery Partner, AWS Systems Manager Service Delivery Partner, Amazon RDS Service Delivery Partner, AWS CloudFormation Service Delivery Partner, AWS Config, Amazon EMR and many more.

WRITTEN BY Deepa Dharanendra Saibannavar
Comments