Cognito and application identity
Identity is not permission
A fictional repair-ticket application serves two organizations, North and South. Cognito user pools authenticate people and issue tokens; identity pools can exchange supported identities for temporary AWS credentials when direct AWS access is needed. Amplify can host the frontend and help integrate sign-in. An authenticated North employee must still be denied access to South tickets. Use a user pool access token for a protected API and an ID token for client identity information; neither is a substitute for resource authorization. A browser app is a public client: use authorization code with PKCE rather than embedding a client secret.
Verify before trusting claims
A JWT contains encoded claims and a signature; decoding is not verification. Use a maintained verifier with trusted issuer and JWKS, an allowed algorithm, signature verification, expiry, token_use=access and the expected Cognito client_id; check the required scope and audience where configured. ID tokens use aud for the app client. Cache public keys with refresh on rotation; reject unverifiable tokens. Configure API Gateway HTTP API JWT authorization with the intended issuer/audience and route scopes, and enforce token type and resource policy where needed. A valid token can outlive a membership change: read current membership for sensitive operations.
Trace an API request
The client sends a bearer access token and a ticket ID to GET /tenants/north/tickets/t1. The authorizer establishes the subject; the handler looks up current membership and checks read permission for North, then queries using both tenant and ticket ID. Return 401 for missing or invalid authentication; for a valid identity without access return 403 or consistently hide resource existence with 404. The example is a synthetic identity after verification, not a JWT. CORS controls browser cross-origin access to responses; scripts outside browsers can send requests without CORS. CORS is not an authorization boundary.
{ "sub": "north-editor", "token_use": "access", "verified": true}Keep secrets on the server
Frontend bundles and browser network requests are visible to users. Public client IDs and endpoint URLs are configuration, not secrets. Use a backend execution role for AWS access and Secrets Manager for necessary server-only secrets. Never place signing keys or long-lived access keys into Amplify build variables that reach client artifacts. If using cookies, protect session cookies with Secure, HttpOnly and an appropriate SameSite setting and address CSRF; if using bearer tokens, minimize exposure to XSS. Audit subject, tenant, action, result and request ID, not raw tokens. Practice: reject a valid North reader attempting a South request.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Cognito and application identity — knowledge check
Distinguish identity, integration and tenant-safe resource access.
What does a Cognito user pool establish?
What is required before trusting JWT claims?
Which flow suits a browser public client?
North user has a valid token but requests South data. What should the API do?
Which value belongs in a frontend bundle?