A developer is implementing user authentication for a web application. The application must allow users to register and sign in directly using their email addresses. Once signed in, the client application needs to invoke a secured REST API hosted on Amazon API Gateway. The developer wants to validate user sessions at the API Gateway layer while minimizing operational overhead and avoiding custom token-validation code.
Which configuration should the developer implement to meet these requirements?
- AUse an Amazon Cognito Identity Pool to manage user registration and authentication. Create a Cognito Authorizer on the API Gateway REST API to validate the credentials.
- Use an Amazon Cognito User Pool to manage user registration and authentication. Configure a Cognito User Pool Authorizer on the API Gateway REST API and pass the ID token in the authorization header of the requests.Answer
- CUse an Amazon Cognito User Pool to manage user registration and authentication. Create a custom API Gateway Lambda Authorizer that parses the user pool token, downloads the JSON Web Key Set (JWKS), and manually validates the signature.
- DUse an Amazon Cognito Identity Pool to authenticate users. Configure a custom Lambda Authorizer on API Gateway that assumes the authenticated IAM role by configuring the IAM role's trust policy to trust the API Gateway service principal.
Answer
Use an Amazon Cognito User Pool to manage user registration and authentication, configure a Cognito User Pool Authorizer on the API Gateway REST API, and pass the ID token in the authorization header of the requests.
The correct configuration uses an Amazon Cognito User Pool because it manages the user directory, sign-up, and sign-in, returning standard JSON Web Tokens (JWTs). Configuring a built-in Cognito User Pool Authorizer on the API Gateway REST API allows API Gateway to natively inspect the authorization header and validate the Cognito ID token without custom-written validation logic.
Step-by-Step Solution
Key Concept
API Gateway integration with Amazon Cognito User Pools for standard authentication flows
Estimated Time:1m 30s