Simplifying User Authentication with Amazon Cognito and Google Integration

Cloud Engineer | AWS Community Builder
Search for a command to run...

Cloud Engineer | AWS Community Builder
Informative blog, I also make blogs around AWS You can check it out
You have a working Amazon EKS cluster and deployed pods. Now, your pods need secure, fine-grained access to AWS services like S3, DynamoDB, or Secrets Manager, but: You don't want to hardcode AWS cre

As your team and projects grow, managing a single EKS cluster can get complicated. You'll likely have different teams like a "Backend Team" and a "Frontend Team" all needing to deploy their applicatio

Serverless computing with AWS Lambda is one of the most powerful ways to run code in the cloud without managing servers. But when a Lambda function is placed inside a VPC (Virtual Private Cloud) to co

Modern developers want fast CI/CD but without storing long-lived AWS keys.By combining Amazon ECS (Fargate), Amazon ECR, GitHub Actions, and OpenID Connect (OIDC) you can deploy securely and automatic

Learn Bash Scripting: A Beginner's Guide Table of Contents Introduction Bash Scripting Basics Variables and User Input Conditional Statements Loops and Iterations Functions Working with Files Scripting Best Practices Conclusion 1. Introdu...

User authentication is a critical component of modern web and mobile applications. Implementing secure and user-friendly authentication can be a complex task. However, with the powerful combination of Amazon Cognito and Google integration, developers can streamline the authentication process while leveraging the security and convenience of Google accounts. In this blog, we will explore how to integrate Google Sign-In with Amazon Cognito, allowing you to enhance your application's user experience and security.
Amazon Cognito is a fully managed service by AWS that provides authentication, authorization, and user management for your applications. It offers several benefits:
Scalability: Amazon Cognito can handle millions of users, ensuring your application scales effortlessly as your user base grows.
Security: It supports industry-standard protocols, including OpenID Connect and OAuth 2.0, ensuring secure authentication and authorization flows.
Flexibility: Amazon Cognito supports various authentication methods, including social identity providers like Google, enabling you to offer multiple login options to your users.
User Management: It provides comprehensive user management features, such as user registration, user profile management, and password resets, reducing the development effort required for these functionalities.

Enable the Google Sign-In API for your project. Set up the OAuth consent screen to configure and register the application.

Select the External and click on CREATE.
App information, App logo, App domain, Developer contact information, Test users must be configured as per the requirement for registering the app.
Configure the authorized JavaScript origins and redirect URIs for your application.
In the application type, multiple options are available, as of now select Web application.

In the next click CREATE OAuth client ID. Authorized redirect URIs will be set up later.

After this Client ID and Client Secret will be provided which will be used to set up google as federated identity provider in the step later.
Create a user pool in Amazon Cognito to manage user registration and authentication.
Search the Amazon Cognito service and click on Create user pool

In the authentication providers select Federated Identity providers





Now map the attributes between Google and user pool

Provide the favorable user pool name

Set up the app client and choose whether to generate client secret or not.

Provide the domain name for Hosted UI and OAuth 2.0 endpoints. The domain name must be unique.
Set up the callback URL to redirect the user back after authentication,=.

In the advanced app client setting select identity provider and OAuth 2.0 grant types. The Implicit Grant is an OAuth 2.0 authorization flow used in web applications. It's suitable for JavaScript-based applications running in web browsers or environments where client secrets cannot be securely stored. In this flow, the client application directly obtains the access token from the authorization server without a separate token exchange step. It involves redirecting the user to the authorization server, authentication, and granting permission.

Now, at last click on Create user pool
Go to the Google developer console in the Authorised redirect URI's and provide the URI's as:
Copy
https://yourDomainPrefix.auth.region.amazoncognito.com/oauth2/idpresponse
Replace yourDomainPrefix and region accordingly from the values of user pool. and SAVE.
Select User pool created above and Click on App integration

At the bottom select the corresponding app client name you created earlier

In the hosted click on View Hosted UI

The output can be seen as below where sign in with google is available.

Successfully User Authentication with Amazon Cognito and Google Integration is done. This can also be integrated with own hosted UI's in own website.