A developer is securing a REST API hosted on Amazon API Gateway for a serverless application. External third-party partner systems must programmatically access this API using a machine-to-machine authentication flow. The partner systems do not have AWS accounts and support only the OAuth 2.0 Client Credentials grant flow. The developer wants to enforce authorization at the API Gateway layer with minimal custom code and low maintenance overhead. Which configuration should the developer implement?
- Configure a Cognito User Pool with a resource server and custom scopes. Define an app client for the partner systems with the Client Credentials grant flow enabled. In API Gateway, create a Cognito User Pool authorizer to validate the access tokens, and configure the API method to require the authorizer and custom scopes.Answer
- BConfigure a Cognito Identity Pool to authenticate the partner systems using anonymous guest access. Grant the partner systems temporary AWS credentials to sign their requests using AWS Signature Version 4 (SigV4), and enable IAM authorization on the API Gateway methods.
- CConfigure a Cognito User Pool with a resource server and client credentials. In API Gateway, create a custom Lambda authorizer that retrieves the JSON Web Key Set (JWKS) from Cognito, decodes and validates the signature of the incoming JWT access token, and returns an IAM policy. Configure the API method to use this Lambda authorizer.
- DEnable Lambda Proxy integration on API Gateway to forward the requests to a backend Lambda function. Within the backend Lambda function code, parse the Authorization header, extract the access token, and perform custom validation against client client_id and client_secret pairs stored in AWS Systems Manager Parameter Store.
Answer
Configure a Cognito User Pool with a resource server and custom scopes. Define an app client for the partner systems with the Client Credentials grant flow enabled. In API Gateway, create a Cognito User Pool authorizer to validate the access tokens, and configure the API method to require the authorizer and custom scopes.
The correct configuration leverages Amazon Cognito User Pools with a Resource Server to support the OAuth 2.0 Client Credentials flow. External partner systems can obtain an access token and pass it to API Gateway. The built-in Cognito User Pool authorizer natively validates these access tokens and checks for the required custom scopes. This requires zero custom code and operates at the API Gateway layer, minimizing maintenance overhead and execution cost.
Step-by-Step Solution
Key Concept
Using built-in Cognito User Pool authorizers with OAuth 2.0 Client Credentials flow for machine-to-machine API authorization.