AWS Cognito authentication with Bearer token
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Understanding AWS Cognito with Bearer Token Authentication
Amazon Web Services (AWS) offers Cognito as its user identity and authentication management service. AWS Cognito simplifies the integration of authentication features into applications, enabling developers to focus on other core components without worrying about user management infrastructure. A common method for protecting APIs and microservices is through Bearer Token Authentication, a scheme allowing access through a token, which is often acquired via OAuth 2.0 or OpenID Connect (OIDC).
Key Concepts
- AWS Cognito: AWS Cognito provides user pools and identity pools, which are foundational to its service offering. A user pool is a user directory in Amazon Cognito that enables you to manage sign-up and sign-in functionality. It integrates with third-party identity providers, like Google and Facebook, to offer flexibility in managing an application's user identities.
- Bearer Token Authentication: In web API security, a bearer token is a one-time use, unique value passed to an API endpoint to assess the calling party's identity. Bearer tokens often leverage JSON Web Tokens (JWTs) and can be validated to ensure the sender’s authenticity without needing the user's credentials repeatedly.
- JSON Web Tokens (JWT): JWTs are compact, URL-safe, and leverages JSON objects for claims representation. AWS Cognito generates JSON Web Tokens when a user authenticates successfully, and this token can be used as a bearer token to access AWS resources secured by AWS Cognito.
Setting Up Cognito with Bearer Token
- Create a Cognito User Pool: A user pool is your primary source of management for user authentication. Start by logging into AWS Management Console, navigating to Cognito, and creating a user pool. Configure it to your requirements for sign-up and sign-in.
- Configure App Client: Under your user pool, set up an App Client. The App Client is a representation of your application in the context of Sign-Up and Sign-In functionality. Configure the security settings and ensure it generates a client secret.
- Obtain User Tokens: Users authenticate by submitting their credentials, and upon successful authentication, Cognito returns a set of tokens: ID Token, Access Token, and Refresh Token. The Access Token can serve as a bearer token for API calls.
- Signature verification using the JWKS endpoint of your Cognito User Pool.
- Expiry to verify the token is still valid.
- Issuer claim (`iss`) to confirm the token fits the expected authentic issuer.
Related reading
- AWS Cognito Best practice to handle same user with same email address signing in from different identity providers Google, Facebook
- AWS Cognito delete-custom-attributes?
- AWS Cognito Error 'identityPoolId' failed to satisfy constraint
- AWS Cognito integration with a beta HTTP API in API Gateway?
- AWS Cognito; unauthorized_client error when hitting /oauth2/token
- AWS Cognito User Pool without a password
- AWS Cognito username/email login is case-sensitive
- AWS cognito What's the difference between Access and Identity tokens?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.