Cloud concept · Updated

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.

In short

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.

Cloud Concepts Hub →

6 key aspects of JSON Web Tokens

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

01
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.

02
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.

03
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.

04
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.

05
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.

06
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 CognitoAmazon 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.

Amazon API GatewayAmazon 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.

AWS AppSyncAWS 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.

AWS LambdaAWS 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.

JSON Web Tokens exam questions

Real practice exam questions on JSON Web Tokens, with the correct answer and its explanation. Answer them with every option in the exam simulator.

SAP-C03

A company uses an Amazon Cognito user pool to authenticate users of a distributed application. Multiple backend services independently validate JWT access tokens. Each service currently has one public signing key embedded in its deployment package. A signing-key rotation caused authentication failures until all services were redeployed.

The company requires signing-key rotation to work without redeployment. When a service encounters a token with an unfamiliar signing-key identifier, it must attempt to obtain the matching key from the trusted endpoint before rejecting the request. If that key is available and the token passes validation, the service must accept that same request rather than wait for a scheduled refresh. During brief endpoint outages, services must continue accepting otherwise valid tokens whose keys are already in an unexpired local cache. Tokens without a trusted matching key must be rejected. Requests with cached keys must not require a network call to the identity provider.

All proposed solutions enforce RS256 and validate the configured issuer, expiration, token_use, allowed client_id, and required scopes. The company permits a bounded local signing-key cache.

Which signing-key management strategy meets these requirements?

Show answerCORRECT ANSWER

Cache keys from the configured user pool's JWKS endpoint and select them by kid. Refresh periodically and attempt a rate-limited refresh on an unknown kid before deciding the request. Accept the request if the retrieved key establishes a valid signature and all claims pass validation. Use unexpired cached keys during endpoint outages, and reject tokens if a trusted matching key remains unavailable.

The configured user pool's JWKS endpoint provides the trusted signing keys, and kid identifies the appropriate key. Refreshing on a cache miss allows the same request to succeed after rotation when the matching key is available. Cached keys avoid network calls for normal requests and support brief outages. Rejecting tokens without a trusted matching key preserves fail-closed behavior, while rate limiting reduces abuse of the refresh path.

Practice JSON Web Tokens in a full exam

Questions on JSON Web Tokens in each practice exam, with every answer option and an explanation for each:

Start a free practice exam

What is JSON Web Tokens

3 min read

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.

Learn JSON Web Tokens in lessons

2 short lessons on JSON Web Tokens in 1 certification course.

Open the lessons