AWS Cognito: User management and authentication

Avatar
Lisa Ernst · 18.10.2025 · Technology · 5 min

AWS Cognito provides a reliable and scalable solution for user management and authentication for web and mobile applications without having to run your own identity backend. The service integrates external identity providers and issues standard-compliant tokens for APIs. In addition, it enables exchanging identity tokens for temporary AWS credentials for direct access to AWS services such as S3 and DynamoDB.

AWS Cognito Fundamentals

AWS Cognito consists of two core components: User Pools and Identity Pools.

User Pools are a user directory and a OpenID-Connect-kompatibler Identity Provider. They authenticate users, issue ID-, Access-, and Refresh-tokens, and integrate social or enterprise IdPs via OIDC or SAML.

Identity Pools (also called Federated Identities) provide based on these identities kurzlebige AWS-Credentials. This is also possible for guests who are not yet signed in.

The managed sign-in page, formerly known as “Hosted UI” and today referred to as “Managed Login,” provides standardkonforme OAuth-Endpunkte ready, including /oauth2/authorize, /oauth2/token, /logout as well as the OIDC Discovery- OIDC Discovery- and JWKS-Ressourcen. For Single Page Applications (SPAs) the Authorization-Code-Flow mit PKCE is crucial, as it prevents intercepted codes from being misused.

The issued tokens are JSON Web Tokens (JWTs). Access Tokens carry scopes and groups for API authorization, while ID Tokens contain profile information. The signatures of these tokens can be verified against the JWKS URL of the respective pool.

Current status & features

Token lifetimes can be precisely configured per app client. Access- and ID-tokens can be configured between 5 Minuten und 1 Tag Refresh-Tokens have a default validity of 30 days, which can be adjusted between 60 Minuten und 10 Jahren that can be adjusted.

The Managed-Login pages support PKCE standardmäßig. The Logout-Endpunkt ends the browser session and redirects to configured sign-out URLs.

Overview of the core features of Amazon Cognito.

Quelle: aws.amazon.com

Overview of the core features of Amazon Cognito.

For a customized brand experience and the use of own domains, a Custom Domain mit einem ACM-Zertifikat can be set up (certificate in us-east-1 required). After that, login occurs via your own subdomain.

APIs can either be protected directly at the API Gateway with a JWT-Authorizer protected, that accepts Cognito as an OIDC issuer, or through a custom (Lambda-)Authorizer.

The adaptive/risikobasierte Anmeldung („Threat Protection“) It can classify suspicious login attempts, enforce Multi-Factor Authentication (MFA), or block access.

For multi-tenant applications AWS documents various patterns, ranging from a Single-Pool-Ansatz bis hin zu einem Pool pro Tenant, including isolation via groups/roles and scopes.

The integration into Next.js applications is simplified by the Cognito-Provider von NextAuth it. Sessions are managed via JWTs/Cookies, and Edge Middleware protects routes.

Background & Motivation

Modern applications require a centralized identity layer that supports industry standards such as OIDC/OAuth2/SAML supports, addresses risks via MFA and adaptive authentication, and at the same time enables integration of own identity providers. For SPAs, PKCE unverzichtbar, as client secrets cannot be securely stored in the browser; Cognito fully implements PKCE.

On the API side, the direct JWT-Abgleich am API Gateway approach is attractive. It offers low latency, a clear separation of authentication (AuthN) and authorization (AuthZ), and avoids an extra round trip to the user store.

Compliance and data residency are further important aspects. User Pools store profile data regionally. Optional features like Pinpoint Analytics can send data to other regions, which is relevant for EU/CH teams and besondere Beachtung erfordert.

Quelle: YouTube

This video shows the SAML-Föderation mit Cognito, which is helpful for visually understanding IdP-based scenarios and single logout.

Practical application & recommendations

If you are developing an SPA or Next.js app, you should choose the Authorization Code Flow mit PKCE choose. Tokens should be stored server-side in httpOnly cookies or use the framework's session mechanism. JWT verification should always be performed against the JWKS-Endpunkt des Pools against the

Typical authentication flow with AWS Cognito.

Quelle: economize.cloud

Typical authentication flow with AWS Cognito.

APIs should verify scopes and implement a mechanism to decouple authentication and authorization and keep latencies low. JWT-Authorizer For multi-tenant applications it is advisable to start with a

to begin, supplemented by tenant attributes or scopes. In case of strict isolation requirements, a pool per tenant can be considered. Single-Pool-Ansatz In the Operations area it is advisable,

to enable monitoring of quotas and login patterns and optionally the CloudTrail und CloudWatch-Metriken to use. Threat Protection

In terms of compliance, regional data flows (e.g., via analytics) must be checked and documented for EU/CH teams, especially considering the regionalen Datenüberlegungen.

Quelle: YouTube

This walkthrough helps to understand Authorization-Code-Flow mit PKCE end-to-end.

Open Questions & Challenges

The design of token TTLs and rotation must be carefully weighed to strike a balance between UX and security level, without forcing applications to constant refresh. AWS recommends using tokens for only about 75 Prozent ihrer Lebenszeit to use and only then renew.

The question arises how far tenant isolation via groups/scopes is sufficient before a pool split becomes organizationally and cost-wise necessary. AWS sketches both paths, but robust thresholds are anwendungsabhängig.

Integration of Cognito with external identity providers and AWS services.

Quelle: aws.amazon.com

Integration of Cognito with external identity providers and AWS services.

Which data may leave the region according to the respective compliance rules when optional features like Pinpoint are active? Here are the regionalen Hinweise to be checked and opt-ins documented.

The consistency of Single Logout across all connected IdPs is another challenge. For SAML there are SLO-Unterstützung, but the implementation details vary by IdP.

Conclusion: AWS Cognito provides a solid, standards-based authentication core with clear extension points: Managed Login with PKCE, clean JWT verification and optional federation to social or enterprise IdPs. In practice, it is crucial to choose the right flow for the application, deliberately limit token lifetimes, and strictly authorize the API layer via scopes. When planning multi-tenant architectures, decisions about isolation boundaries and operational metrics should be made early. The building blocks are in place, and the design decision lies with the user.

Teilen Sie doch unseren Beitrag!