A developer is designing a secure integration for an enterprise application. While human users authenticate interactively via an Amazon Cognito User Pool, an external partner’s automated service must programmatically invoke a specific Amazon API Gateway REST API. The partner's service needs to perform machine-to-machine (M2M) communication without any user interaction. Which configuration meets these requirements with the least operational overhead?
- Configure a resource server in the Cognito User Pool and define a custom scope. Create a user pool client for the partner service, enable the Client Credentials grant flow, and configure the API Gateway method to use a Cognito authorizer that requires the custom scope.Answer
- BCreate a custom API Gateway Lambda authorizer. Instruct the partner service to send its client credentials in the Authorization header. In the authorizer Lambda function, call the Cognito InitiateAuth API to validate the credentials on each request.
- CSet up an Amazon Cognito Identity Pool using developer-authenticated identities. Write a backend authentication service to verify the partner service, exchange credentials for temporary IAM credentials, and secure the API Gateway REST API using IAM authorization.
- DConfigure a user pool client with the Authorization Code grant flow. Instruct the partner service to authenticate and obtain an ID token, then implement custom token validation logic in the backend Lambda function to verify the token signature on each request.
Answer
Configure a resource server in the Cognito User Pool and define a custom scope. Create a user pool client for the partner service, enable the Client Credentials grant flow, and configure the API Gateway method to use a Cognito authorizer that requires the custom scope.
Configuring a Cognito resource server and using the Client Credentials grant flow allows machine-to-machine clients to obtain OAuth 2.0 access tokens. API Gateway Cognito authorizers can natively validate these access tokens and restrict access based on the configured custom scopes. This requires no custom validation code or external identity pools.
Step-by-Step Solution
Key Concept
Amazon Cognito User Pool Resource Servers and Client Credentials Flow