A developer is building a partner portal API using an Amazon API Gateway REST API. External partner organizations will access this API using JSON Web Tokens (JWTs) issued by their own external OAuth 2.0 Identity Provider (IdP). The developer needs to secure the API so that requests are authorized only if the JWT is valid and contains a specific custom scope.
Which approach should the developer use to meet these security requirements with the least administrative and operational overhead?
- Configure a Lambda authorizer on the REST API to validate the incoming JWT signature, parse the custom scopes, and return an IAM policy to API Gateway.Cevap
- BConfigure an Amazon Cognito User Pools authorizer on the REST API, pointing the Token Source to the external Identity Provider's token verification endpoint.
- CCreate an Amazon Cognito Identity Pool to federate the external Identity Provider, configure the REST API to use IAM authorization, and require partner clients to sign their HTTP requests with Signature Version 4.
- DConfigure a Lambda proxy integration for the REST API methods, and implement custom code within the backend Lambda function to validate the JWT and return HTTP 401 Unauthorized for invalid tokens.
Cevap
Configure a Lambda authorizer on the REST API to validate the incoming JWT signature, parse the custom scopes, and return an IAM policy to API Gateway.
The correct approach is to configure a Lambda authorizer on the REST API. Since API Gateway REST APIs do not have a native JWT authorizer for third-party token validation (unlike HTTP APIs), a Lambda authorizer is required to run custom logic. The Lambda authorizer receives the bearer token, validates its signature against the external Identity Provider's public keys, checks the custom scopes, and returns an IAM policy that allows or denies access. This keeps the authorization logic at the API Gateway tier, protecting the backend.
Adım Adım Çözüm
Anahtar Kavram
API Gateway Lambda Authorizers for Third-Party JWT Validation