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: AWS Terraform, Java Programming Lab Challenges, Azure DP-900 & DP-300 Certification Exam Prep, Plus Plenty More Amazon, Google, Microsoft, and Big Data Courses
This month our Content Team continues building the catalog of courses for everyone learning about AWS, GCP, and Microsoft Azure. In addition, this month’s updates include several Java programming lab challenges and a couple of courses on big data. In total, we released five new learning...
Where Should You Be Focusing Your AWS Security Efforts?
Another day, another re:Invent session! This time I listened to Stephen Schmidt’s session, “AWS Security: Where we've been, where we're going.” Amongst covering the highlights of AWS security during 2020, a number of newly added AWS features/services were discussed, including: AWS Audit...
AWS re:Invent: 2020 Keynote Top Highlights and More
We’ve gotten through the first five days of the special all-virtual 2020 edition of AWS re:Invent. It’s always a really exciting time for practitioners in the field to see what features and services AWS has cooked up for the year ahead. This year’s conference is a marathon and not a...
WARNING: Great Cloud Content Ahead
At Cloud Academy, content is at the heart of what we do. We work with the world’s leading cloud and operations teams to develop video courses and learning paths that accelerate teams and drive digital transformation. First and foremost, we listen to our customers’ needs and we stay ahea...
Excelling in AWS, Azure, and Beyond – How Danut Prisacaru Prepares for the Future
Meet Danut Prisacaru. Danut has been a Software Architect for the past 10 years and has been involved in Software Engineering for 30 years. He’s passionate about software and learning, and jokes that coding is basically the only thing he can do well (!). We think his enthusiasm shines t...
New Content: AWS Data Analytics – Specialty Certification, Azure AI-900 Certification, Plus New Learning Paths, Courses, Labs, and More
This month our Content Team released two big certification Learning Paths: the AWS Certified Data Analytics - Speciality, and the Azure AI Fundamentals AI-900. In total, we released four new Learning Paths, 16 courses, 24 assessments, and 11 labs. New content on Cloud Academy At any ...
New Content: Azure DP-100 Certification, Alibaba Cloud Certified Associate Prep, 13 Security Labs, and Much More
This past month our Content Team served up a heaping spoonful of new and updated content. Not only did our experts release the brand new Azure DP-100 Certification Learning Path, but they also created 18 new hands-on labs — and so much more! New content on Cloud Academy At any time, y...
AWS Certification Practice Exam: What to Expect from Test Questions
If you’re building applications on the AWS cloud or looking to get started in cloud computing, certification is a way to build deep knowledge in key services unique to the AWS platform. AWS currently offers 12 certifications that cover major cloud roles including Solutions Architect, De...
Overcoming Unprecedented Business Challenges with AWS
From auto-scaling applications with high availability to video conferencing that’s used by everyone, every day — cloud technology has never been more popular or in-demand. But what does this mean for experienced cloud professionals and the challenges they face as they carve out a new p...
Constant Content: Cloud Academy’s Q3 2020 Roadmap
Hello — Andy Larkin here, VP of Content at Cloud Academy. I am pleased to release our roadmap for the next three months of 2020 — August through October. Let me walk you through the content we have planned for you and how this content can help you gain skills, get certified, and...
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...
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...