A developer is building a mobile application that authenticates users through an Amazon Cognito User Pool. The application then exchanges the user's JSON Web Token (JWT) for temporary AWS credentials using an Amazon Cognito Identity Pool. These credentials are used to sign requests to an Amazon API Gateway REST API using AWS Signature Version 4 (SigV4). However, the API Gateway method is configured with a Cognito User Pool Authorizer, and all signed requests are failing with a 401 Unauthorized error. How should the developer resolve this authorization failure?
- Modify the API Gateway method's authorization type to AWS_IAM to allow authorization of requests signed with temporary IAM credentials.Cevap
- BReplace the Cognito User Pool Authorizer with a custom Lambda authorizer to parse and validate the AWS Signature Version 4 signature manually.
- CConfigure the client application to send the Cognito Identity Pool ID directly in the Authorization header as a bearer token instead of using Signature Version 4 signing.
- DInitialize the API Gateway client in the mobile application by hardcoding the IAM role's permanent access key and secret key.
Cevap
Modify the API Gateway method's authorization type to AWS_IAM to allow authorization of requests signed with temporary IAM credentials.
Changing the API Gateway authorization type to AWS_IAM allows API Gateway to natively validate the Signature Version 4 (SigV4) headers. Since Cognito Identity Pools issue temporary IAM credentials associated with an IAM role (either authenticated or unauthenticated), the API Gateway method must be configured to use AWS_IAM authorization to allow access based on these IAM permissions.
Adım Adım Çözüm
Anahtar Kavram
Resolving Cognito User Pool vs. Identity Pool API Gateway Authorization failures by switching to AWS_IAM authorization for SigV4 signed requests.
Tahmini Süre:1m 30s