microservice-test, collection, event-driven,

How to automate API an User login if the authentication of application is using AWS Auth - Cognito

Donald Donald Follow Jan 01, 2024 · 1 min read
How to automate API an User login if the authentication of application is using AWS Auth - Cognito
Share this

How to automate API an User login if the authentication of application is using AWS Auth - Cognito

Cognito AWS Auth

You can refer to this link: AWS Cognito

https://docs.aws.amazon.com/cognito/latest/developerguide/what-is-amazon-cognito.html

walking assets/images/microservice-testing/how-to-automate-api-user-login-aws-cognito/Untitled.png

Automated test script to login app with Cognito:

In order to do E2E automated test script for your application with Auth Cognito AWS, we follow Cognito Guide from AWS.

https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_InitiateAuth.html

Before we implement more test scripts to cover testing for internal function of your app, you need to login your app by your credential information, then you can have the token of your test-account.

The below command in CURL command helps you to make an auth request to AWS Cognito to get account token.

walking

curl --location --request POST 'https://cognito-idp..amazonaws.com/' \
--header 'Content-Type: application/x-amz-json-1.1' \
--header 'X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth' \
--data-raw '{
    "AuthParameters" : {
        "USERNAME" : ,
        "PASSWORD" : 
    },
    "AuthFlow" : "USER_PASSWORD_AUTH",
    "ClientId" : 
}'

                               — Copyright 2024 — 
Join Newsletter
Get the latest news right in your inbox. We never spam!
Donald
Written by Donald
Hi, I am Donald (Doai Tran), the author of Testing4Everyone. I hope you like it!