What is Cognito in AWS?

Web applications usually allow a valid username and password combination for successful sign in to the application. Modern authentication flows incorporate more approaches to ensure user authentication. When using AWS, this is no exception, thanks to the abilities and features offered by AWS Cognito.

Amazon Cognito service is designed to provide APIs and infrastructure for key features in user management space such as authentication, authorization, and managing user repository with different operations for your web and mobile apps. This blog is part of the AWS Solutions Architect – Associate Certification Preparation. This learning path is specifically designed to prepare you for the AWS Certified Solutions Architect – Associate exam released in March 2020.

AWS Solutions Architect – Associate Certification Preparation

Modern authentication flows

You might have come across some of the methods as mentioned below:

  • Email OTP method enables you to authenticate using the one-time password (OTP) that is sent to the registered email address as part of multi-factor authentication.
  • Login challenges are meant to be answering more security questions to prevent access where there is mistrust.
  • In some websites, you could sign in through your Google account or Facebook account as well. For example, the Cloud Academy login page also provides such flexibility in sign in.
  • Nowadays, once we login to a corporate network we don’t need to log in again to access internal applications. We are able to access internal applications without re-login.
  • You might have noticed that once you login to any of the google applications such as Gmail,  google drive you would be able to access other google applications too without providing user credentials again.

Source: Cloud Academy login page

In today’s world, we might be wondering how we are going to build essential features with respect to user management, authentication, and authorization in our web applications and mobile applications efficiently. It requires a significant amount of development activities, testing activities, adherence to security compliance standards and exposure to authentication standards.

Payment gateways

Let me recall how other specific requirements are managed in web applications. For example, many web applications have pages for payment. These payment pages provide flexible options to pay using credit cards, net banking, etc. In a typical web application, they integrate  API services from any of the third-party payment gateways to fulfill all requirements in a simple manner.

Payment gateways facilitate payment transactions between customers and banks. These payment gateways also take care of the security of the transactions and adherence to standards such as PCI DSS(Payment Card Industry Data Security Standard). Hence the product teams can focus on core functionalities of their web and mobile applications without putting too much focus on handling payment transactions.

Can we apply the same approach for signup, sign-in, and user management features especially in aws cloud? Yes. It’s a good approach to leverage third-party service provider solutions for authentication as well. Luckily we have got Amazon Cognito to help us to manage things better.

What is Amazon Cognito?

This service allows users to log in directly with their user credentials that are maintained in Amazon Cognito on behalf of of your web and mobile applications. It also allows sign-in through a third party social networking application such as Facebook, Amazon, Google or Apple, and other Identity providers.

Amazon Cognito provides important features to achieve different use cases in user management and authentication in web applications and mobile applications.

Let us have a quick look at Amazon Cognito features before we move on to key components of the AWS Cognito service and overall architecture.

  • Managing user directory – Amazon user pools are used as user directories to store user’s personal data such as login id,  password, etc. This information will be used during sign-in for validation. As this is a cloud service from AWS, We need not worry about managing infrastructure, setup and scaling the service. We could store even millions of user details if required.
  • Integrate with social network logins and federated identity providers – Amazon Cognito accepts and allows sign in for users who have an account in social networking sites such as Facebook, Google, PayPal without the need to create a new account in Amazon Cognito.  This feature is also available if a user sign-in through an external identity provider(IdP) that is compatible to OpenID Connect and SAML 2.0.
  • Standards-based authentication- OpenID Connect, OAuth 2.0, and SAML 2.0.
  • Security for your apps and users – HIPAA eligible and PCI DSS, SOC, and ISO/IEC 27001, ISO/IEC 27017, ISO/IEC 27018, and ISO 9001 compliant.
  • Simple integration with your app – Amazon Cognito provides software development kit(SDK) for Android, iOS, and Javascript to call APIs that implement user sign-up and sign-in functionality. In addition to providing simple APIs, Amazon Cognito also comes with a default and customizable UI page for user sign-up and sign-in.
  • Role-based access control for AWS resources – An AWS IAM role has specific permissions to access AWS resources. You could use identity pools to map users to specific roles and authorize their access to AWS resources.

Key components of Amazon Cognito

In general, any user management and identity management services are built upon two key functions namely authentication and authorization.

Authentication is the process of validating your claims on identity. For example, You could prove your identity with a passport for security check-in airport.

Authorization is the process to provide confirmation on your access rights to other AWS resources and services. For example, you could show a boarding pass to get into the flight.

User pool and identity pool are two main components in Amazon Cognito. User pools are nothing but a repository where user profile details are kept. When new users signup using your web or mobile applications this user pool will be updated.  As a result when users sign-in,  their credentials would be authenticated against data in the user pool.

Identity pools simplify authenticated user access to other AWS resources. Identity pool issues temporary AWS credentials to your user’s so that they could access other AWS resources without re-entering their credentials. Amazon Cognito is flexible enough to allow usage of user pools and identity pools separately. They can be used together as well.

In the enterprise intranet network, users sign in using user id and password. If the user id and password are validated successfully they can enter the network. This function is called authentication and performed by user pool.

If they want to access some internal services or resources they don’t need to re-enter their login credentials. They will be authorized to use the service based on policies and rules configured. This authorization is enabled by some service that provides either login credentials of the user or issues temporary access tokens to access other servers or resources. This function is called authorization and performed by the identity pool.

In simple words, the authentication function is performed before the authorization is done. OpenID Connect is one of the references for authentication whereas OAuth 2.0 is one of the references for authorization.

Now we shall see how user pools and identity pools perform authentication and authorization in aws.

Amazon Cognito user pool overview

A user pool is a user directory in Amazon Cognito. This component takes care of providing authentication to users who sign in through your web or mobile application. Once a user is authenticated, Amazon Coginitio returns user pool tokens to your application. It also allows social sign in from Google etc and sign-in with SAML identity providers.

Source: Using Tokens with User Pools

Source: Amazon Cognito User Pools

These tokens can be classified into ID token and access token. Your users could perform the following activities by using these tokens.

Your client web and mobile applications can access your own server-side components such as a database.

Source: Access Your Server-side Resources with a User Pool

You can provide option to your users to access your API using API Gateway. API Gateway validates the tokens and uses them to grant your users access to resources including Lambda functions, or your own API

Source: Access Resources with API Gateway and Lambda with a User Pool

Your client applications can exchange these tokens for temporary AWS credentials to access other AWS services from the identity pool of Amazon Cognito.

Source: Access AWS Services with a User Pool and an Identity Pool

You could refresh tokens as well as they expire one hour after authentication. We could also revoke these tokens if required.

User pool also provides the following features.

  • Import CSV file contents into the user pool where the CSV file contains existing user’s credentials.
  • User pool comes with sign-up and sign-in features and a ready-made, customizable web UI to sign in users.
  • User directory management and user profiles.
  • It supports various security features such as multi-factor authentication (MFA) and checks for compromised credentials.
  • It provides features such as account takeover protection, and verification through phone and email.
  • It helps us to create customized workflows and support user migration through AWS Lambda triggers.

Amazon Cognito API for developers – User pool

If you are from software development background you would be interested to know about user authentication flow.

We could configure different authentication workflows by configuring a set of challenges in the user pool. Based on authentication flow, the user needs to answer further challenges until authentication either fails or the user assigned tokens. Ther is a sequence of request and response API calls shown below. The following APIs are used: InitiateAuth and RespondToAuthChallenge. RespondToAuthChallenge can be repeated to include different challenges so that we can support any custom authentication flow.

Source: User Pool Authentication Flow

Amazon Cognito pools

Amazon Cognito identity pool

Identity pool authorizes users to access other AWS services without further user authentication. Identity pool help to create identities for users and assign permissions for them using IAM roles. Using the Identity pool, users can get access to other AWS services based on their identity information.

An identity pool can include:

  • Users from Amazon Cognito user pool
  • Users from who can authenticate from external identity providers such as Facebook and Google
  • Users authenticated from user own authentication process

Source: Authenticate with a Third Party and Access AWS Services with an Identity Pool 

Identity pools also support unauthenticated users such as guest user access as well.

There are only four steps involved with an identity pool.

  1. Authenticate user from Amazon User pool or external identity providers or your identity provider
  2. Create an identity for them in Amazon Cognito after authenticating the user
  3. Get OpenID token from Amazon Cognito
  4. Get temporary AWS credentials tokens from Amazon Cognito once they share the OpenID token. Using temporary AWS credentials tokens,  the user can access any AWS service or resource based on assigned IAM roles for their identities as long as access token is not expired.

Amazon Cognito API for developers – Identity pool

Amazon Cognito supports multiple flows such as basic flow and enhanced flow. Let us a look at the enhanced flow. In the below diagram, GetId creates an identity in Amazon Cognito. GetCredntialsForIdentity gets a valid OpenID Connect token and it exchanges this token with AWS STS. By this step, your application gets temporary credentials to access other AWS resources.

Source: Identity Pools (Federated Identities) Authentication Flow

So far we have seen the usage of Amazon Cognito User pool for authentication purposes. Then we saw four steps in Amazon Cognito Identity pool to access other AWS services for authenticated users. We also covered one scenario where both user pool and identity pool used together as part of the authentication workflow.

As a recap, let us list a few scenarios that could use Amazon Cognito.

  • Users can be authenticated with a user pool in AWS Cognito
  • Users can be authenticated to use server-side resources
  • Users are authorized to use resources with API Gateway and Lambda
  • Users are allowed to use other AWS resources without re-login by combined usage of user pool and identity pool
  • Integrating support for authentication from third-party Identity providers and social logins

Amazon Cognito pool use cases

Here is a list of few more suggested use cases from Amazon Cognito in alignment with what we covered above.

User pool use cases

Web and mobile application developers can use a user pool when you need to:

  • Embed a default sign-up and sign-in page in your client-side applications
  • To avail typical user management features as a proven readily available module
  • To monitor trends in usage and reconstruct sign-in request flows from the perspective of security based on the user device, location, and IP address
  • To build a custom authentication flow based on your specific user management requirements

Identity pool use cases

Web and mobile application developers can use an identity pool when you need to:

  • Grant permitted access to your authenticated users to access other AWS resources such an Amazon Simple Storage Service (Amazon S3) bucket or an Amazon DynamoDB table
  • Grant temporary default access to guest users who are not authenticated

Needless to say, it also enables us to give better user experience as mentioned below.

  • Reduce password fatigue from maintaining different username and password combinations
  • Eliminate time spent re-entering passwords for the same identity
  • Lower IT costs due to less number of IT help desk calls about passwords
  • Mitigate risk for access to 3rd-party sites where profile data is not managed  and stored securely
  • Gain better control over your online user credentials and identity
  • To speed up Sign Up Process at your favorite web applications and services

I hope you have got an introduction to Amazon Cognito with an overview of major components such as user pool and identity pool with architecture to support various use cases. If you have any questions or feedback, please drop it as a comment below.

Vijayakumar Athithan

Written by

Vijayakumar Athithan

Vijay is the founder of Margazhi System Networks LLP that provides consultancy in the network security R&D. He also teaches classes on various subjects especially on programming, Linux, cloud, and network security in the capacity of guest faculty during weekends. Prior to that, he gained a decade of experience in different roles in reputed IT service companies across the globe. He has earned the following certifications: SCJP, SCBCD, PMP, ITIL, Exin-Cloud, and CEH.


Related Posts

Alisha Reyes
Alisha Reyes
— August 5, 2020

New Content: Alibaba, Azure AZ-303 and AZ-304, Site Reliability Engineering (SRE) Foundation, Python 3 Programming, 16 Hands-on Labs, and Much More

This month our Content Team did an amazing job at publishing and updating a ton of new content. Not only did our experts release the brand new AZ-303 and AZ-304 Certification Learning Paths, but they also created 16 new hands-on labs — and so much more! New content on Cloud Academy At...

Read more
  • AWS
  • Azure
  • DevOps
  • Google Cloud Platform
  • Machine Learning
  • programming
Alisha Reyes
Alisha Reyes
— July 16, 2020

Blog Digest: Which Certifications Should I Get?, The 12 Microsoft Azure Certifications, 6 Ways to Prevent a Data Breach, and More

This month, we were excited to announce that Cloud Academy was recognized in the G2 Summer 2020 reports! These reports highlight the top-rated solutions in the industry, as chosen by the source that matters most: customers. We're grateful to have been nominated as a High Performer in se...

Read more
  • AWS
  • Azure
  • blog digest
  • Certifications
  • Cloud Academy
  • OWASP
  • OWASP Top 10
  • Security
  • VPCs
Avatar
Cloud Academy Team
— July 9, 2020

Which Certifications Should I Get?

The old AWS slogan, “Cloud is the new normal” is indeed a reality today. Really, cloud has been the new normal for a while now and getting credentials has become an increasingly effective way to quickly showcase your abilities to recruiters and companies.With all that in mind, the s...

Read more
  • AWS
  • Azure
  • Certifications
  • Cloud Computing
  • Google Cloud Platform
Alisha Reyes
Alisha Reyes
— July 2, 2020

New Content: AWS, Azure, Typescript, Java, Docker, 13 New Labs, and Much More

This month, our Content Team released a whopping 13 new labs in real cloud environments! If you haven't tried out our labs, you might not understand why we think that number is so impressive. Our labs are not “simulated” experiences — they are real cloud environments using accounts on A...

Read more
  • AWS
  • Azure
  • DevOps
  • Google Cloud Platform
  • Machine Learning
  • programming
Joe Nemer
Joe Nemer
— June 19, 2020

Kickstart Your Tech Training With a Free Week on Cloud Academy

Are you looking to make a jump in your technical career? Want to get trained or certified on AWS, Azure, Google Cloud Platform, DevOps, Kubernetes, Python, or another in-demand skill?Then you'll want to mark your calendar. Starting Monday, June 22 at 12:00 a.m. PDT (3:00 a.m. EDT), ...

Read more
  • AWS
  • Azure
  • cloud academy content
  • complimentary access
  • GCP
  • on the house
Alisha Reyes
Alisha Reyes
— June 11, 2020

New Content: AZ-500 and AZ-400 Updates, 3 Google Professional Exam Preps, Practical ML Learning Path, C# Programming, and More

This month, our Content Team released tons of new content and labs in real cloud environments. Not only that, but we introduced our very first highly interactive "Office Hours" webinar. This webinar, Acing the AWS Solutions Architect Associate Certification, started with a quick overvie...

Read more
  • AWS
  • Azure
  • DevOps
  • Google Cloud Platform
  • Machine Learning
  • programming
Rebecca Willis
Rebecca Willis
— June 3, 2020

Azure vs. AWS: Which Certification Provides the Brighter Future?

More and more companies are using cloud services, prompting more and more people to switch their current IT position to something cloud-related. The problem is most people only have that much time after work to learn new technologies, and there are plenty of cloud services that you can ...

Read more
  • AWS
  • Azure
  • certification
Alisha Reyes
Alisha Reyes
— June 2, 2020

Blog Digest: 5 Reasons to Get AWS Certified, OWASP Top 10, Getting Started with VPCs, Top 10 Soft Skills, and More

Thank you for being a valued member of our community! We recently sent out a short survey to understand what type of content you would like us to add to Cloud Academy, and we want to thank everyone who gave us their input. If you would like to complete the survey, it's not too late. It ...

Read more
  • AWS
  • Azure
  • blog digest
  • Certifications
  • Cloud Academy
  • OWASP
  • OWASP Top 10
  • Security
  • VPCs
Alisha Reyes
Alisha Reyes
— May 11, 2020

New Content: Alibaba, Azure Cert Prep: AI-100, AZ-104, AZ-204 & AZ-400, Amazon Athena Playground, Google Cloud Developer Challenge, and much more

This month, our Content Team released 8 new learning paths, 4 courses, 7 labs in real cloud environments, and 4 new knowledge check assessments. Not only that, but we introduced our very first course on Alibaba Cloud, and our expert instructors are working 'round the clock to create 6 n...

Read more
  • alibaba
  • AWS
  • Azure
  • gitops
  • Google Cloud Platform
  • lab playground
  • programming
Avatar
Rhonda Martinez
— May 4, 2020

Top 5 Reasons to Get AWS Certified Right Now

Cloud computing trends are on the rise and have been for some time already. Fortunately, it’s never too late to start learning cloud computing. Skills like AWS and others associated with cloud computing are in high demand because cloud technologies have become crucial for many businesse...

Read more
  • Amazon Elastic Book Store
  • Amazon Elastic Compute Cloud (EC2)
  • AWS
  • AWS Certifications
  • Glacier
Alisha Reyes
Alisha Reyes
— May 1, 2020

Introducing Our Newest Lab Environments: Lab Playgrounds

Want to train in a real cloud environment, but feel slowed down by spinning up your own deployments? When you consider security or pricing costs, it can be costly and challenging to get up to speed quickly for self-training. To solve this problem, Cloud Academy created a new suite of la...

Read more
  • AWS
  • Azure
  • Docker
  • Google Cloud Platform
  • Java
  • lab playgrounds
  • Python
Alisha Reyes
Alisha Reyes
— April 30, 2020

Blog Digest: AWS Breaking News, Azure DevOps, AWS Study Guide, 8 Ways to Prevent a Ransomware Attack, and More

  New articles by topicAWS Azure Data Science Google Cloud  Cloud Adoption Platform Updates & New Content Security Women in TechAWSBreaking News: All AWS Certification Exams Now Available Online As an Advanced AWS Technology Partner, C...

Read more
  • AWS
  • Azure
  • blog digest
  • Certifications
  • Cloud Academy
  • programming
  • Security