A developer is implementing a custom backend service hosted on Amazon ECS that processes requests from a mobile application. The mobile application authenticates users via an Amazon Cognito User Pool and includes the obtained JSON Web Token (JWT) in the Authorization header of each API request. To minimize latency, the developer wants the backend service to validate these tokens locally rather than making network calls to Amazon Cognito for every incoming request.
Which process should the developer implement to validate the incoming JWTs?
- Download and cache the JSON Web Key Set (JWKS) from the Cognito User Pool endpoint, match the token's key ID (kid) to a key in the JWKS, verify the cryptographic signature using the corresponding public key, and validate the token's expiration, audience, and issuer claims.Cevap
- BExchange the User Pool JWT for temporary AWS credentials by calling the Cognito Identity Pools API, and then check the token's validity using the AWS Security Token Service (STS).
- CConfigure a custom API Gateway Lambda Authorizer to intercept each ECS request, forward the JWT to the Cognito User Pool GetUser endpoint, and let Cognito validate the token on behalf of the backend service.
- DUse an Amazon Cognito Identity Pool to obtain a symmetric AWS Key Management Service (AWS KMS) data key, decrypt the JWT payload on the backend service, and inspect the decrypted claims.
Cevap
The correct process is to download and cache the JSON Web Key Set (JWKS) from the Cognito User Pool endpoint, locate the matching public key using the key ID (kid) header, verify the cryptographic signature, and validate the claims locally (expiration, audience, and issuer).
The correct approach is to retrieve the public JSON Web Key Set (JWKS) from the Cognito User Pool's public URI and cache it. When a request arrives, the backend service parses the JWT header to find the key ID (kid), verifies the cryptographic signature with the matching public key, and then verifies the claims locally (expiration, audience, and issuer). This avoids any network call during request processing.
Adım Adım Çözüm
Anahtar Kavram
Local validation of Amazon Cognito User Pool JWTs
Tahmini Süre:1m 30s