A company needs to integrate an on-premises backend daemon service with a REST API hosted on AWS behind Amazon API Gateway. The daemon service must perform automated, non-interactive batch uploads to the API. Security requirements state that authentication must be handled via Amazon Cognito, leveraging OAuth 2.0 flows, and the service must be granted only the specific scope required for writing data (api/write). How should the developer configure Cognito and the daemon service to implement this authentication flow?
- ACreate a Cognito Identity Pool that permits unauthenticated access. Have the daemon service exchange its client credentials for temporary AWS credentials using the Cognito Identity Pool API, and sign the HTTP requests to API Gateway using AWS Signature Version 4.
- BConfigure a Cognito User Pool App Client with the Authorization Code grant. Implement a custom Lambda Authorizer on the API Gateway REST API to perform the OAuth 2.0 token exchange with Cognito, validate the returned ID token, and cache the authorization decision.
- Configure a Cognito User Pool with an App Client that has a client secret, enabling the Client Credentials grant flow and defining a custom scope of 'api/write'. Have the daemon service request an access token from the Cognito token endpoint, and use a Cognito User Pool authorizer on API Gateway to validate the token.Cevap
- DConfigure an IAM Role with a trust policy that allows the Cognito User Pool to assume the role. Instruct the daemon service to call the Cognito authentication endpoint to assume this IAM Role, and then use the returned temporary credentials to sign requests to API Gateway.
Cevap
Configure a Cognito User Pool with an App Client that has a client secret, enabling the Client Credentials grant flow and defining a custom scope of 'api/write'. Have the daemon service request an access token from the Cognito token endpoint, and use a Cognito User Pool authorizer on API Gateway to validate the token.
The Client Credentials grant flow is the standard OAuth 2.0 flow for machine-to-machine (M2M) or server-to-server authentication where no interactive user is present. By configuring a Cognito User Pool App Client with a client secret, enabling the Client Credentials flow, and defining custom resource scopes (like 'api/write'), the backend daemon service can securely request a JWT access token directly from the Cognito OAuth 2.0 token endpoint. API Gateway can then validate this access token natively using a Cognito User Pool Authorizer without requiring custom code.
Adım Adım Çözüm
Anahtar Kavram
Implementing machine-to-machine authentication using the Cognito User Pool Client Credentials grant flow and validating access tokens using an API Gateway Cognito User Pool Authorizer.
Tahmini Süre:2m 30s