How to Simulate AWS Cognito Login in Postman

Published: (March 11, 2026 at 07:33 AM EDT)
7 min read
Source: Dev.to

Source: Dev.to

Testing a Cognito‑protected backend with Postman

When you need a valid authentication token without using your frontend, you can call the Cognito Identity Provider (IDP) directly. This guide shows the exact steps—from IAM credentials to a successful 200 OK response containing an AccessToken.


Prerequisites

Requirement
1Access to the AWS Console with permissions to view Cognito and IAM
2The AWS region where your Cognito User Pool is deployed (e.g., us-east-2)
3An IAM user with programmatic access – you’ll need the Access Key ID and Secret Access Key
4Your Cognito App Client ID (found under User Pool → App clients)
5A test user in the User Pool (username + password)
6USER_PASSWORD_AUTH enabled on the App Client (see below)

1️⃣ Enable USER_PASSWORD_AUTH

Cognito supports several authentication flows.

  • USER_PASSWORD_AUTH – accepts a plain‑text username & password in a single request (ideal for direct API testing).
  • USER_SRP_AUTH – challenge‑based SRP flow; does not expose credentials in transit.

⚠️ Only enable USER_PASSWORD_AUTH in development / staging. In production you should prefer USER_SRP_AUTH or token‑based flows.

How to enable

  1. Open the AWS Console → CognitoUser PoolsYour PoolApp clients.
  2. Select your client → scroll to Authentication flows.
  3. Check ALLOW_USER_PASSWORD_AUTH (if not already checked).
  4. Click Save changes.

2️⃣ Store IAM credentials securely (Postman Vault)

The Cognito IDP endpoint (https://cognito-idp..amazonaws.com/) requires SigV4 signing, so you need valid AWS credentials.

  1. In the AWS Console go to IAMUsersYour UserSecurity credentials.
  2. Under Access keys, create or copy the Access Key ID and Secret Access Key.

Never hard‑code these values in shared Postman environments.
Instead, use Postman Vault (local‑only storage):

Vault entryValue
access_keyYour IAM Access Key ID
secret_keyYour IAM Secret Access Key

Reference them in requests as {{vault:access_key}} and {{vault:secret_key}}.

3️⃣ Configure AWS Signature Authorization in Postman

  1. Create a new POST request

    POST https://cognito-idp..amazonaws.com/
  2. Authorization tabAuth Type: AWS Signature

    FieldValue
    Add auth toRequest Headers
    AccessKey{{vault:access_key}}
    SecretKey{{vault:secret_key}}
    AWS Regione.g., us-east-2
    Service Namecognito-idp
    Session Token(leave blank unless using STS)

    Postman will automatically generate the Authorization header and all required X‑Amz‑* headers.

  3. Headers tab – add the required static headers

    KeyValue
    Content-Typeapplication/x-amz-json-1.1
    X-Amz-TargetAWSCognitoIdentityProviderService.InitiateAuth
    X-Amz-User-Agentaws-amplify/5.0.4 auth framework/5
  4. Body tabrawJSON

    {
      "AuthFlow": "USER_PASSWORD_AUTH",
      "ClientId": "your_app_client_id_here",
      "AuthParameters": {
        "USERNAME": "testuser@yourdomain.com",
        "PASSWORD": "YourTestPassword"
      }
    }

    Replace ClientId, USERNAME, and PASSWORD with your actual values.

  5. Click Send.

4️⃣ Expected successful response

{
  "AuthenticationResult": {
    "AccessToken": "eyJraW...",
    "ExpiresIn": 3600,
    "IdToken": "eyJraW...",
    "RefreshToken": "eyJjb...",
    "TokenType": "Bearer"
  },
  "ChallengeParameters": {}
}
  • Use the AccessToken (or IdToken, depending on your backend) as a Bearer token in the Authorization header of subsequent API calls.

5️⃣ Common error responses & fixes

ErrorLikely causeFix
UnrecognizedClientException / InvalidSignatureExceptionWrong/expired IAM credentials, wrong region, or wrong service name (cognito-idp)Verify Vault values, AWS Region, and Service Name fields
InvalidParameterException: USER_PASSWORD_AUTH flow not enabledApp client lacks ALLOW_USER_PASSWORD_AUTHRe‑enable the flow in Cognito App Client settings
NotAuthorizedException: Incorrect username or passwordBad test credentials or user does not existCheck the user’s username/password in the Cognito console
**400 Bad Request (no body)Missing or incorrect X-Amz-Target headerEnsure X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth is present
MissingAuthenticationTokenRequest not signed (Auth Type not set to AWS Signature)Re‑apply the AWS Signature auth configuration

TL;DR Checklist

  1. Enable USER_PASSWORD_AUTH on the App client.
  2. Create IAM access key & store it in Postman Vault.
  3. Set up a POST request to https://cognito-idp..amazonaws.com/.
  4. Configure AWS Signature auth (Vault variables, region, service).
  5. Add required headers (Content-Type, X‑Amz‑Target, X‑Amz‑User-Agent).
  6. Send the JSON payload with AuthFlow: USER_PASSWORD_AUTH.
  7. Extract the AccessToken (or IdToken) for downstream API calls.

You now have a reproducible, fully‑documented way to obtain Cognito tokens directly from Postman—perfect for backend testing, CI pipelines, or debugging authentication issues. Happy testing!

Common Cognito IDP Errors

ErrorDescriptionFix
MissingAuthenticationTokenExceptionSigV4 signing is not configured or the credentials are empty.Verify that Postman Vault values are resolving correctly – red‑highlighted vault references in the Authorization tab indicate unresolved secrets.
UserNotConfirmedExceptionThe test user account has not been confirmed.Confirm the user via email/SMS verification, or manually confirm the user in the AWS Console → CognitoUsers[User]Confirm.

Why Test the Cognito Auth Endpoint Directly?

Testing the endpoint gives you more than just a token; it validates the entire authentication pipeline:

  • App Client ID is correct and the auth flow is properly configured.
  • IAM permissions are scoped correctly for the test environment.
  • The test user is in a confirmed and active state.
  • Token expiry (ExpiresIn: 3600) matches your session‑management expectations.
  • The response structure aligns with what your frontend or API consumer expects.

If downstream APIs rely on the IdToken for claims‑based authorization (e.g., checking cognito:groups or custom attributes), you can decode the JWT locally with tools like jwt.io to inspect the payload without any extra calls.

From Manual Postman Test → Automated JMeter Test

  1. Manual step – Get the token in Postman.
  2. Automation step – In JMeter, use an HTTP Sampler to perform the same InitiateAuth call, then extract AccessToken with a JSON Extractor and pass it to subsequent samplers as a variable.

Tip: For CI/CD‑integrated test suites, store test credentials in AWS Secrets Manager or Parameter Store and fetch them at runtime instead of embedding them in scripts or collection files.

Step‑by‑Step Action List

StepAction
1Confirm USER_PASSWORD_AUTH is enabled on the Cognito App Client.
2Retrieve IAM Access Key and Secret Key.
3Store the credentials in Postman Vault.
4Configure AWS Signature auth in the Authorization tab.
5Add the required headers: Content-Type, X-Amz-Target, X-Amz-User-Agent.
6Build the JSON body with AuthFlow, ClientId, and AuthParameters.
7Send the request and extract the token from AuthenticationResult.

Sample Request (JSON Body)

{
  "AuthFlow": "USER_PASSWORD_AUTH",
  "ClientId": "",
  "AuthParameters": {
    "USERNAME": "",
    "PASSWORD": ""
  }
}

Closing Thoughts

Direct Cognito API testing is a foundational skill for anyone working with AWS‑backed systems. It:

  • Removes the dependency on a running frontend.
  • Speeds up token acquisition during test setup.
  • Provides clear visibility into how your authentication layer behaves at the protocol level.

Mastering this workflow will make your debugging, performance testing, and CI/CD pipelines far more reliable.

0 views
Back to Blog

Related posts

Read more »