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.
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.
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.
- 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.
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
Your client applications can exchange these tokens for temporary AWS credentials to access other AWS services from the identity pool of Amazon Cognito.
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
Identity pools also support unauthenticated users such as guest user access as well.
There are only four steps involved with an identity pool.
- Authenticate user from Amazon User pool or external identity providers or your identity provider
- Create an identity for them in Amazon Cognito after authenticating the user
- Get OpenID token from Amazon Cognito
- 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.
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.
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...
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...
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...
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...
AWS Certified Solutions Architect Associate: A Study Guide
Want to take a really impactful step in your technical career? Explore the AWS Solutions Architect Associate certificate. Its new version (SAA-C02) was released on March 23, 2020, though you can still take SAA-C01 through July 1, 2020. This post will focus on version SAA-C02.The AWS...
New on Cloud Academy: AWS Solutions Architect Exam Prep, Azure Courses, GCP Engineer Exam Prep, Programming, and More
Free content on Cloud Academy More and more customers are relying on our technology and content to keep upskilling their people in these months, and we are doing our best to keep supporting them. While the world fights the COVID-19 pandemic, we wanted to make a small contribution to he...
Breaking News: All AWS Certification Exams Now Available Online
Remote proctoring for all AWS certifications Cloud Academy is an Advanced AWS Technology Partner, and we are happy to announce all AWS certification exams are available online! What does this mean for you? You can stay focused on your certification goal. Or you can start a certifica...
How To Build a Career with AWS Certifications
From Iaas and PaaS solutions to digital marketing, cloud computing reshapes the world of technology. As the influence of this technology grows, so does investment. Tens of billions of dollars are being spent on cloud computing-related services each year. This influx is continuing to inc...
The 12 AWS Certifications: Which is Right for You and Your Team?
As companies increasingly shift workloads to the public cloud, cloud computing has moved from a nice-to-have to a core competency in the enterprise. This shift requires a new set of skills to design, deploy, and manage applications in cloud computing.As the market leader and most ma...
Cloud Academy’s Blog Digest: How Do AWS Certifications Increase Your Employability, How to Become a Microsoft Certified Azure Data Engineer, and more
With everything going on right now, it's likely that the only thing you've been reading lately is related to the coronavirus pandemic. It's important to stay informed during these times, but it's also good to jump into something that can take your mind off of the current situation for j...
Which Certifications Should I Get?
As we mentioned in an earlier post, 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 compan...
New on Cloud Academy: Intro to GitOps; AWS Courses; Java, Python, Amazon Linux 2, Ubuntu, & Docker Playgrounds; and much more
New Lab Playgrounds This month, our Content Team released six new "playground labs." Our playground labs provide a safe and secure sandbox environment for you to explore your own ideas, follow along with Cloud Academy courses, or answer your own questions — all without having to instal...