CLOUD CONCEPT

JSON Web Tokens

JSON Web Tokens are a standardized format for carrying claims between parties, commonly used as signed bearer tokens for application authentication and authorization.

Cloud Concepts Hub →

What is JSON Web Tokens

A JSON Web Token (JWT) carries claims about a subject, its issuer, and its validity, allowing an API to evaluate a request without retrieving a server-side session for every call. Secure use requires verifying the token and enforcing authorization rules; merely decoding its contents does not establish trust.

A JSON Web Token (JWT) is a standardized container for claims exchanged between systems. Claims can identify a user or application, name the issuing authority, specify intended recipients, and define validity times. JWT is a token format, not an authentication protocol or an authorization policy. OAuth 2.0 access tokens can use JWT format, while OpenID Connect ID tokens use JWTs to communicate authentication information to clients.

The signed JWT commonly used by cloud APIs has three base64url-encoded segments separated by periods: a header, a payload, and a signature. The header identifies the signing algorithm and may include a key identifier, or kid. The payload contains claims. A valid signature provides integrity and authenticity under the verifier's configured trust model, but it does not conceal the payload. Anyone holding an ordinary signed JWT can decode its claims, so passwords, secrets, and unnecessary personal information should not appear there. Encrypted JWTs also exist, but encryption must not be assumed.

In a typical application, a client authenticates with an identity provider and receives an access token. It sends that token to an API using the Authorization header with the Bearer scheme, over HTTPS. Bearer means that possession is sufficient to present the credential; an attacker who steals it can generally replay it until it expires or an applicable revocation mechanism rejects it. Tokens should not appear in URLs, application logs, or error messages. Browser storage choices must account for script-based theft and, when cookies are used, cross-site request forgery.

A resource server must verify the signature using trusted keys and an explicitly permitted algorithm. It must also validate the expected issuer, expiration, applicable not-before time, intended audience or required client binding, and token purpose. Do not trust a token simply because its signature is mathematically valid: it might belong to another application or be an ID token rather than an API access token. Retrieve verification keys only from trusted configuration, commonly an issuer's JSON Web Key Set endpoint, and support key rotation with controlled caching.

Authentication establishes who presented the request; authorization determines what that identity may do. For example, an orders API might require an orders.read scope and then verify that the requested order belongs to the authenticated subject or tenant. A valid token alone does not grant access to every record. With Amazon Cognito and an Amazon API Gateway HTTP API, an issuer can provide tokens while a JWT authorizer validates them and checks configured route scopes. Backend code must still enforce resource-level business permissions.

Local signature verification reduces session-store lookups and supports horizontally scaled services. The trade-off is that claims can become stale: removing a role or signing a user out does not necessarily invalidate an already issued token at a locally verifying API. Short-lived access tokens limit this window, while refresh-token controls, deny lists, or additional state checks address stronger revocation requirements at an operational cost. Finally, JWTs are not AWS access keys: calling most AWS service APIs requires AWS credentials and Signature Version 4, even when a JWT was used earlier to authenticate the user.

Key aspects of JSON Web Tokens

JWT security depends on trusted claim verification, careful bearer-token handling, explicit authorization, and deliberate lifecycle controls.

Claims-based identity context

Claims communicate information such as subject, issuer, audience, and expiration. Keep claims minimal and define which claims each API requires rather than assuming every issuer uses the same structure.

Integrity without automatic confidentiality

A signed JWT protects against undetected modification when its signature is properly verified. Base64url encoding does not encrypt its contents, so ordinary signed JWTs must not carry secrets.

Bearer-token security

An API commonly accepts an access JWT through the Authorization: Bearer header. Protect the token in transit, storage, telemetry, and client code because possession generally permits replay.

Explicit verification and trust

Allow only expected algorithms, use trusted verification keys, and check issuer, validity times, intended recipient, and token purpose. Decoding claims without verification must never authorize a request.

Separate authentication from authorization

Use verified identity and scopes as inputs to authorization, not as a substitute for it. Enforce tenant boundaries, ownership, and operation-specific permissions in the appropriate API or backend layer.

Expiration, rotation, and revocation

Short token lifetimes reduce exposure from theft and stale claims, while verification-key rotation limits long-term key risk. Immediate revocation usually requires additional state or issuer-specific enforcement beyond local signature checks.

Cloud services for JSON Web Tokens

Amazon Cognito can authenticate users and issue JWTs that clients present to Amazon API Gateway or AWS AppSync. API Gateway HTTP API JWT authorizers validate configured issuer and audience requirements and can require route scopes, while AppSync applies its configured authorization model to GraphQL requests. Lambda authorizers support custom validation when built-in mechanisms do not fit. Backend functions and resolvers still enforce ownership, tenant boundaries, and business permissions. Across these components, coordinate token lifetimes, trusted issuers, verification-key rotation, and logging controls so tokens remain protected and authorization remains consistent.

Amazon Cognito image Amazon Cognito

Amazon Cognito user pools issue signed JWT access tokens and ID tokens after authentication. APIs should use access tokens for authorization and validate the appropriate claims, including token_use, rather than treating ID and access tokens as interchangeable.

Open Amazon Cognito →
Amazon API Gateway image Amazon API Gateway

HTTP APIs support JWT authorizers that validate tokens from configured issuers and can enforce route-level scopes. REST APIs offer Cognito user pool authorizers or Lambda authorizers instead; the HTTP API JWT authorizer is not a universal feature across all API types.

Open Amazon API Gateway →
AWS AppSync image AWS AppSync

AWS AppSync supports authorization through Amazon Cognito user pools and OpenID Connect providers using JWTs. Schema authorization settings and resolver logic must restrict access to the correct operations and data.

Open AWS AppSync →
AWS Lambda image AWS Lambda

Lambda functions can implement custom token validation and policy decisions as API Gateway Lambda authorizers. Backend functions can also enforce record ownership and tenant isolation using claims supplied through a trusted authorization path.

Open AWS Lambda →