AWS, Cloud Computing

4 Mins Read

A Guide to User Authentication in Amazon Cognito using Python – Part 2

Voiced by Amazon Polly

Overview

In the previous blog post, we learned how to connect Amazon Cognito registration with Boto3. We made a signup part and set it up with the User Pool. In this new blog, we’ll find out how to do these things: resend a verification code, guide on how to log in to a user in the Amazon Cognito user pool, and handle forgotten and changed passwords using Boto3.

Pioneers in Cloud Consulting & Migration Services

  • Reduced infrastructural costs
  • Accelerated application deployment
Get Started

Introduction

Amazon Cognito is an Amazon Web Services (AWS) service that provides identity and user management for your applications. It’s commonly used to add user registration, authentication, and authorization features to web and mobile apps. Amazon Cognito simplifies handling user identities and securing access to your application’s resources.

Resend Verification Code Using Amazon Cognito, Python SDK Boto3

Imagine you didn’t get the verification code, or your app has a resending button. You can use AWS Cognito to resend the verification code in such cases. Here’s how to do it.

resend

When you execute the above code, you will get this back as a response,

resend2

Log in and get user details using Amazon Cognito, Python SDK Boto3

You’ve just made a new user and confirmed them. Now, the next thing to do is to log in and fetch some information about the user from Amazon Cognito. Here’s how you can do it.

login

Please be aware that sometimes you might encounter this error.

login2

If you come across this error, please go to the Amazon Cognito > User Pool > (Your-user-pool-name) > App integration > Select your App Client and navigate to the Authentication flows Configuration section. Make sure that you have the “ALLOW_USER_PASSWORD_AUTH” option selected. If you’re testing, you can enable all the options like this for testing purposes.

login3

After you use “initiate_auth” you’ll receive a JSON response. You only need to find AccessToken from this response and use it in the “get_user” function. When you do this, you’ll get the following response.

login4

Forgot Password Using Amazon Cognito, Python SDK Boto3

Using this method will send a message to the user. This message contains a code that they need to change their password. It’s an important step in keeping their account secure. Here’s how you can do it.

forgot

When you execute the above code, you will get this back as a response,

forgot2

Confirm Forgot Password using Amazon Cognito, Python SDK Boto3

confirm

You will receive this as a response when you execute the above code.

forgot2

Change the Password of an Existing User using Amazon Cognito

This method helps you change the password for a user with an account. It updates the password for a specific user in a user pool. To use this method, you must have the AccessToken of the user you want to change the password for.

change

When you execute the above code, you will get this back as a response,

change2

Conclusion

Amazon Cognito is a helpful service that handles your user management work. While it may incur some costs, it allows you to concentrate on the exciting parts of your application and not worry about handling user-related tasks.

You can be confident that AWS will handle things like keeping the service up-to-date with the latest security updates so you won’t have to worry about security vulnerabilities.

Drop a query if you have any questions regarding Amazon Cognito and we will get back to you quickly.

Making IT Networks Enterprise-ready – Cloud Management Services

  • Accelerated cloud migration
  • End-to-end view of the cloud environment
Get Started

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 PartnerAWS Migration PartnerAWS Data and Analytics PartnerAWS DevOps Competency PartnerAWS GenAI Competency PartnerAmazon QuickSight Service Delivery PartnerAmazon EKS Service Delivery Partner AWS Microsoft Workload PartnersAmazon EC2 Service Delivery PartnerAmazon ECS Service Delivery PartnerAWS Glue Service Delivery PartnerAmazon Redshift Service Delivery PartnerAWS Control Tower Service Delivery PartnerAWS WAF Service Delivery PartnerAmazon CloudFront Service Delivery PartnerAmazon OpenSearch Service Delivery PartnerAWS DMS Service Delivery PartnerAWS Systems Manager Service Delivery PartnerAmazon RDS Service Delivery PartnerAWS CloudFormation Service Delivery PartnerAWS ConfigAmazon EMR and many more.

FAQs

1. Can I use Amazon Cognito User Pools for single sign-on (SSO) across multiple applications?

ANS: – Yes, Amazon Cognito User Pools can be used for SSO, allowing users to access multiple applications with a single set of credentials.

2. Is it possible to customize the email templates sent by Amazon Cognito for user verification and password reset?

ANS: – Yes, you can customize email templates in Amazon Cognito User Pools to match your application’s branding and messaging.

3. How does Amazon Cognito handle user account recovery, such as forgotten passwords?

ANS: – Amazon Cognito offers built-in account recovery options, including password reset via email or SMS, to help users securely regain access to their accounts.

WRITTEN BY Aritra Das

Aritra Das works as a Research Associate at CloudThat. He is highly skilled in the backend and has good practical knowledge of various skills like Python, Java, Azure Services, and AWS Services. Aritra is trying to improve his technical skills and his passion for learning more about his existing skills and is also passionate about AI and Machine Learning. Aritra is very interested in sharing his knowledge with others to improve their skills.

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!