How to Simulate AWS Cognito Login in Postman
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 |
|---|---|
| 1 | Access to the AWS Console with permissions to view Cognito and IAM |
| 2 | The AWS region where your Cognito User Pool is deployed (e.g., us-east-2) |
| 3 | An IAM user with programmatic access – you’ll need the Access Key ID and Secret Access Key |
| 4 | Your Cognito App Client ID (found under User Pool → App clients) |
| 5 | A test user in the User Pool (username + password) |
| 6 | USER_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_AUTHin development / staging. In production you should preferUSER_SRP_AUTHor token‑based flows.
How to enable
- Open the AWS Console → Cognito → User Pools → Your Pool → App clients.
- Select your client → scroll to Authentication flows.
- Check
ALLOW_USER_PASSWORD_AUTH(if not already checked). - 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.
- In the AWS Console go to IAM → Users → Your User → Security credentials.
- 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 entry | Value |
|---|---|
access_key | Your IAM Access Key ID |
secret_key | Your IAM Secret Access Key |
Reference them in requests as {{vault:access_key}} and {{vault:secret_key}}.
3️⃣ Configure AWS Signature Authorization in Postman
Create a new POST request
POST https://cognito-idp..amazonaws.com/Authorization tab → Auth Type:
AWS SignatureField Value Add auth to Request HeadersAccessKey {{vault:access_key}}SecretKey {{vault:secret_key}}AWS Region e.g., us-east-2Service Name cognito-idpSession Token (leave blank unless using STS) Postman will automatically generate the
Authorizationheader and all requiredX‑Amz‑*headers.Headers tab – add the required static headers
Key Value Content-Typeapplication/x-amz-json-1.1X-Amz-TargetAWSCognitoIdentityProviderService.InitiateAuthX-Amz-User-Agentaws-amplify/5.0.4 auth framework/5Body tab → raw → JSON
{ "AuthFlow": "USER_PASSWORD_AUTH", "ClientId": "your_app_client_id_here", "AuthParameters": { "USERNAME": "testuser@yourdomain.com", "PASSWORD": "YourTestPassword" } }Replace
ClientId,USERNAME, andPASSWORDwith your actual values.Click Send.
4️⃣ Expected successful response
{
"AuthenticationResult": {
"AccessToken": "eyJraW...",
"ExpiresIn": 3600,
"IdToken": "eyJraW...",
"RefreshToken": "eyJjb...",
"TokenType": "Bearer"
},
"ChallengeParameters": {}
}- Use the
AccessToken(orIdToken, depending on your backend) as a Bearer token in theAuthorizationheader of subsequent API calls.
5️⃣ Common error responses & fixes
| Error | Likely cause | Fix |
|---|---|---|
UnrecognizedClientException / InvalidSignatureException | Wrong/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 enabled | App client lacks ALLOW_USER_PASSWORD_AUTH | Re‑enable the flow in Cognito App Client settings |
NotAuthorizedException: Incorrect username or password | Bad test credentials or user does not exist | Check the user’s username/password in the Cognito console |
**400 Bad Request (no body) | Missing or incorrect X-Amz-Target header | Ensure X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth is present |
MissingAuthenticationToken | Request not signed (Auth Type not set to AWS Signature) | Re‑apply the AWS Signature auth configuration |
TL;DR Checklist
- Enable
USER_PASSWORD_AUTHon the App client. - Create IAM access key & store it in Postman Vault.
- Set up a POST request to
https://cognito-idp..amazonaws.com/. - Configure
AWS Signatureauth (Vault variables, region, service). - Add required headers (
Content-Type,X‑Amz‑Target,X‑Amz‑User-Agent). - Send the JSON payload with
AuthFlow: USER_PASSWORD_AUTH. - Extract the
AccessToken(orIdToken) 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
| Error | Description | Fix |
|---|---|---|
| MissingAuthenticationTokenException | SigV4 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. |
| UserNotConfirmedException | The test user account has not been confirmed. | Confirm the user via email/SMS verification, or manually confirm the user in the AWS Console → Cognito → Users → [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
- Manual step – Get the token in Postman.
- Automation step – In JMeter, use an HTTP Sampler to perform the same
InitiateAuthcall, then extractAccessTokenwith 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
| Step | Action |
|---|---|
| 1 | Confirm USER_PASSWORD_AUTH is enabled on the Cognito App Client. |
| 2 | Retrieve IAM Access Key and Secret Key. |
| 3 | Store the credentials in Postman Vault. |
| 4 | Configure AWS Signature auth in the Authorization tab. |
| 5 | Add the required headers: Content-Type, X-Amz-Target, X-Amz-User-Agent. |
| 6 | Build the JSON body with AuthFlow, ClientId, and AuthParameters. |
| 7 | Send 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.