Skip to content

Cognito

AWSim emulates two Cognito services: User Pools (cognito-idp) and Identity Pools (cognito-identity).


User Pools (cognito-idp)

Protocol: AwsJson1_1 (X-Amz-Target: AWSCognitoIdentityProviderService.*) Signing name: cognito-idpTarget Prefix: AWSCognitoIdentityProviderServicePersistent: Yes

Quick Start (User Pools)

Create a pool, add a client, create a user, and sign in:

bash
# Create a user pool
POOL_ID=$(curl -s http://localhost:4566 \
  -H "Content-Type: application/x-amz-json-1.1" \
  -H "X-Amz-Target: AWSCognitoIdentityProviderService.CreateUserPool" \
  -H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/cognito-idp/aws4_request, SignedHeaders=host, Signature=fake" \
  -d '{"PoolName":"my-pool"}' \
  | jq -r '.UserPool.Id')

# Create a client
CLIENT_ID=$(curl -s http://localhost:4566 \
  -H "Content-Type: application/x-amz-json-1.1" \
  -H "X-Amz-Target: AWSCognitoIdentityProviderService.CreateUserPoolClient" \
  -H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/cognito-idp/aws4_request, SignedHeaders=host, Signature=fake" \
  -d "{\"UserPoolId\":\"$POOL_ID\",\"ClientName\":\"my-app\",\"ExplicitAuthFlows\":[\"ALLOW_USER_PASSWORD_AUTH\",\"ALLOW_REFRESH_TOKEN_AUTH\"]}" \
  | jq -r '.UserPoolClient.ClientId')

# Create a user and set password
curl -s http://localhost:4566 \
  -H "Content-Type: application/x-amz-json-1.1" \
  -H "X-Amz-Target: AWSCognitoIdentityProviderService.AdminCreateUser" \
  -H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/cognito-idp/aws4_request, SignedHeaders=host, Signature=fake" \
  -d "{\"UserPoolId\":\"$POOL_ID\",\"Username\":\"[email protected]\",\"TemporaryPassword\":\"Temp@123!\"}"

curl -s http://localhost:4566 \
  -H "Content-Type: application/x-amz-json-1.1" \
  -H "X-Amz-Target: AWSCognitoIdentityProviderService.AdminSetUserPassword" \
  -H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/cognito-idp/aws4_request, SignedHeaders=host, Signature=fake" \
  -d "{\"UserPoolId\":\"$POOL_ID\",\"Username\":\"[email protected]\",\"Password\":\"MyPassword123!\",\"Permanent\":true}"

# Sign in
curl -s http://localhost:4566 \
  -H "Content-Type: application/x-amz-json-1.1" \
  -H "X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth" \
  -H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/cognito-idp/aws4_request, SignedHeaders=host, Signature=fake" \
  -d "{\"AuthFlow\":\"USER_PASSWORD_AUTH\",\"ClientId\":\"$CLIENT_ID\",\"AuthParameters\":{\"USERNAME\":\"[email protected]\",\"PASSWORD\":\"MyPassword123!\"}}"

User Pool Management

OperationDescription
CreateUserPoolCreate a user pool with schema, password policy, MFA settings
DeleteUserPoolDelete a user pool
DescribeUserPoolGet user pool configuration
ListUserPoolsList all user pools
UpdateUserPoolUpdate user pool configuration
AddCustomAttributesAdd custom attributes to the schema

User Pool Clients

OperationDescription
CreateUserPoolClientCreate an app client with explicit auth flows
DescribeUserPoolClientGet client configuration and client secret
UpdateUserPoolClientUpdate client configuration
DeleteUserPoolClientDelete a client
ListUserPoolClientsList all clients

User Management

OperationDescription
SignUpSelf-registration with username and password
ConfirmSignUpConfirm registration with code (use 123456 in AWSim)
AdminConfirmSignUpAdmin-confirm a user without a code
AdminCreateUserCreate a user as admin with temporary password
AdminDeleteUserDelete a user
AdminGetUserGet user details and attributes
AdminSetUserPasswordSet user password (use Permanent: true to skip force-change)
AdminEnableUserEnable a disabled user
AdminDisableUserDisable a user
AdminResetUserPasswordForce password reset on next login
AdminUpdateUserAttributesUpdate user attributes as admin
AdminDeleteUserAttributesDelete user attributes as admin
AdminUserGlobalSignOutSign out all user sessions
ListUsersList users with optional filter expression
GetUserGet current user's attributes (requires access token)
UpdateUserAttributesUpdate current user's attributes
DeleteUserAttributesDelete current user's attributes
DeleteUserDelete the current user
VerifyUserAttributeVerify an attribute (e.g. email)
GetUserAttributeVerificationCodeSend attribute verification code
ResendConfirmationCodeResend confirmation code
RevokeTokenRevoke a refresh token

Authentication

OperationDescription
InitiateAuthStart auth flow: USER_PASSWORD_AUTH, REFRESH_TOKEN_AUTH, USER_SRP_AUTH
AdminInitiateAuthAdmin-initiated auth flow (server-side)
RespondToAuthChallengeRespond to a challenge: NEW_PASSWORD_REQUIRED, SOFTWARE_TOKEN_MFA
AdminRespondToAuthChallengeAdmin respond to challenge
ForgotPasswordInitiate forgot password flow (code is always 123456)
ConfirmForgotPasswordConfirm new password with code
ChangePasswordChange password (requires access token)
GlobalSignOutSign out all sessions for current user

Groups

OperationDescription
CreateGroupCreate a group with optional IAM role
GetGroupGet group details
UpdateGroupUpdate group description or role
DeleteGroupDelete group
ListGroupsList all groups
AdminAddUserToGroupAdd user to group
AdminRemoveUserFromGroupRemove user from group
AdminListGroupsForUserList groups for a user
ListUsersInGroupList users in a group

MFA

OperationDescription
SetUserPoolMfaConfigConfigure MFA for the pool (TOTP, SMS, optional/required)
GetUserPoolMfaConfigGet MFA configuration
AssociateSoftwareTokenBegin TOTP setup — returns a secret key
VerifySoftwareTokenVerify TOTP setup with a valid code
SetUserMFAPreferenceSet user's preferred MFA method
AdminSetUserMFAPreferenceAdmin set user's MFA preference

Resource Servers and Identity Providers

OperationDescription
CreateResourceServerCreate an OAuth resource server with custom scopes
DescribeResourceServerGet resource server
UpdateResourceServerUpdate resource server
DeleteResourceServerDelete resource server
ListResourceServersList resource servers for a pool
CreateIdentityProviderRegister a federated identity provider (SAML, OIDC, social)
DescribeIdentityProviderGet identity provider details
UpdateIdentityProviderUpdate provider details
DeleteIdentityProviderRemove an identity provider
ListIdentityProvidersList identity providers for a pool
GetIdentityProviderByIdentifierFind provider by identifier

Tags

OperationDescription
TagResourceAdd tags to a user pool by ARN
UntagResourceRemove tags from a user pool
ListTagsForResourceList tags for a user pool

Domains

OperationDescription
CreateUserPoolDomainCreate a hosted-UI domain for the pool
DescribeUserPoolDomainDescribe a user pool domain; returns empty if not found
DeleteUserPoolDomainDelete the hosted-UI domain
UpdateUserPoolDomainUpdate the domain custom certificate

Identity Pools (cognito-identity)

Protocol: AwsJson1_1 (X-Amz-Target: AWSCognitoIdentityService.*) Signing name: cognito-identityTarget Prefix: AWSCognitoIdentityServicePersistent: Yes

Identity Pools issue temporary AWS credentials via STS-style credential vending based on IAM role mappings.

Quick Start (Identity Pools)

bash
# Create an identity pool
POOL_ID=$(curl -s http://localhost:4566 \
  -H "Content-Type: application/x-amz-json-1.1" \
  -H "X-Amz-Target: AWSCognitoIdentityService.CreateIdentityPool" \
  -H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/cognito-identity/aws4_request, SignedHeaders=host, Signature=fake" \
  -d '{"IdentityPoolName":"my-identity-pool","AllowUnauthenticatedIdentities":true}' \
  | jq -r '.IdentityPoolId')

# Get credentials for an identity
curl -s http://localhost:4566 \
  -H "Content-Type: application/x-amz-json-1.1" \
  -H "X-Amz-Target: AWSCognitoIdentityService.GetCredentialsForIdentity" \
  -H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/cognito-identity/aws4_request, SignedHeaders=host, Signature=fake" \
  -d "{\"IdentityId\":\"us-east-1:some-identity-id\"}"

Operations

OperationDescription
CreateIdentityPoolCreate an identity pool with authentication providers
DeleteIdentityPoolDelete an identity pool
DescribeIdentityPoolGet pool configuration and role mappings
ListIdentityPoolsList all identity pools
UpdateIdentityPoolUpdate pool configuration (role mappings, providers)
GetIdGet or create an identity ID for a user
GetCredentialsForIdentityGet temporary AWS credentials for an identity

OAuth / OIDC

Cognito User Pools expose full OAuth 2.0 / OIDC endpoints. See Cognito OAuth/OIDC for the hosted login page, token endpoint, JWKS, and NextAuth.js integration.

The hosted UI also exposes a logout endpoint at GET /cognito/{pool_id}/logout that mirrors AWS Cognito:

QueryBehaviour
?client_id=X&logout_uri=YValidates Y against the client's LogoutURLs and 302s there.
?client_id=X&redirect_uri=Y&response_type=codeValidates Y against the client's CallbackURLs and 302s back through /oauth2/authorize.
(neither)400 Bad Request — same as real Cognito.

Admin Console UI

The pool list lives at /cognito. Clicking a pool navigates to /cognito/[poolId] — a full-route detail page with a left-nav covering eight sections:

SectionWhat it covers
UsersServer-side filter (Cognito username ^= prefix), 25 / 50 / 100 per page, Prev/Next pagination via PaginationToken, inline detail (attributes editor + group memberships + auth events viewer), bulk Import CSV that loops AdminCreateUser with progress + error reporting.
GroupsCreate / delete / inline member-list editor with AdminAddUserToGroup / AdminRemoveUserFromGroup.
App clientsCreate + delete with Prev/Next pagination. Inline editor for CallbackURLs, LogoutURLs, AllowedOAuthFlows, AllowedOAuthScopes, ExplicitAuthFlows, plus the AllowedOAuthFlowsUserPoolClient toggle. Client secret is masked with reveal + copy.
DomainHosted-UI Domain from DescribeUserPool plus inline create / delete via CreateUserPoolDomain / DeleteUserPoolDomain.
TriggersEditable map of every Cognito Lambda trigger (PreSignUp, PostConfirmation, CustomMessage, DefineAuthChallenge, CreateAuthChallenge, VerifyAuthChallengeResponse, PreTokenGeneration, UserMigration, CustomEmailSender, CustomSMSSender, …) → Lambda function ARN. Saves via UpdateUserPool.LambdaConfig.
PoliciesPassword policy editor (MinimumLength, Require*, TemporaryPasswordValidityDays), MFA mode (OFF / OPTIONAL / ON) + TOTP factor toggle, tag editor (ListTagsForResource / TagResource / UntagResource).
FederationList / create / edit / delete identity providers (OIDC, SAML, Google, Facebook, SignInWithApple, LoginWithAmazon) with ProviderDetails + AttributeMapping key-value editors. Per-IdP suggested-keys datalist matches the AWS shape. Resource servers + custom OAuth scopes managed in the same tab.
AppearanceUI customization editor — pick scope (pool default or per-app-client), set logo URL + CSS, save via SetUICustomization. Stored for SDK round-trip parity even though awsim's hosted UI doesn't apply the CSS yet.

The active section is URL-synced as ?section=<id> so reloads + share-links land where you left.

SDK Example (User Pools)

typescript
import {
  CognitoIdentityProviderClient,
  CreateUserPoolCommand,
  CreateUserPoolClientCommand,
  AdminCreateUserCommand,
  AdminSetUserPasswordCommand,
  InitiateAuthCommand,
} from '@aws-sdk/client-cognito-identity-provider';

const cognito = new CognitoIdentityProviderClient({
  region: 'us-east-1',
  endpoint: 'http://localhost:4566',
  credentials: { accessKeyId: 'test', secretAccessKey: 'test' },
});

// Create user pool
const { UserPool } = await cognito.send(new CreateUserPoolCommand({
  PoolName: 'my-pool',
  Policies: {
    PasswordPolicy: {
      MinimumLength: 8,
      RequireUppercase: true,
      RequireLowercase: true,
      RequireNumbers: true,
    },
  },
}));
const userPoolId = UserPool!.Id!;

// Create client
const { UserPoolClient } = await cognito.send(new CreateUserPoolClientCommand({
  UserPoolId: userPoolId,
  ClientName: 'my-app',
  ExplicitAuthFlows: ['ALLOW_USER_PASSWORD_AUTH', 'ALLOW_REFRESH_TOKEN_AUTH'],
}));
const clientId = UserPoolClient!.ClientId!;

// Create user with permanent password
await cognito.send(new AdminCreateUserCommand({
  UserPoolId: userPoolId,
  Username: '[email protected]',
  TemporaryPassword: 'Temp@123!',
}));
await cognito.send(new AdminSetUserPasswordCommand({
  UserPoolId: userPoolId,
  Username: '[email protected]',
  Password: 'MyPassword123!',
  Permanent: true,
}));

// Sign in
const { AuthenticationResult } = await cognito.send(new InitiateAuthCommand({
  AuthFlow: 'USER_PASSWORD_AUTH',
  ClientId: clientId,
  AuthParameters: {
    USERNAME: '[email protected]',
    PASSWORD: 'MyPassword123!',
  },
}));

console.log('Access Token:', AuthenticationResult?.AccessToken);
console.log('Refresh Token:', AuthenticationResult?.RefreshToken);

Behavior Notes

  • Email verification and confirmation codes are always 123456 — no real email is sent.
  • SMS-based MFA is accepted but no SMS is delivered — use TOTP or skip verification in tests.
  • Tokens are real JWTs signed with a locally generated RSA key; they can be verified against the JWKS endpoint at http://localhost:4566/{userPoolId}/.well-known/jwks.json.
  • Identity pool credentials are valid for testing SDK calls — they use the AWSim account.

Password policy enforcement

Every password-mutating operation (SignUp, AdminCreateUser, AdminSetUserPassword, ChangePassword, ConfirmForgotPassword) validates against the user pool's Policies.PasswordPolicy. Each rule (minimum length, lowercase, uppercase, numeric, symbol) raises InvalidPasswordException with a rule-specific message matching real Cognito.

Account lockout

Five consecutive failed InitiateAuth / AdminInitiateAuth attempts on the same user lock the account for 15 minutes. Subsequent attempts return NotAuthorizedException with "Password attempts exceeded" even on the right password. A successful login or any administrative password reset clears the counter. (Real Cognito gates this behind Advanced Security; we ship it always-on for local testing.)

Compromised-credentials BLOCK

SetRiskConfiguration with a CompromisedCredentialsRiskConfiguration whose Actions.EventAction is BLOCK (and EventFilter covers SIGN_IN) is honored on every sign-in. Passwords on a built-in compromised list (password, 12345678, qwerty, etc.) are rejected with NotAuthorizedException even when otherwise correct. Real Cognito uses a much larger AWS-curated dataset.

Auth event history

Every sign-in is recorded as an AuthEvent with EventResponse, RiskDecision, RiskLevel, and CompromisedCredentialsDetected flags. AdminListUserAuthEvents returns the most recent 100 events newest-first. (Admin)UpdateAuthEventFeedback mutates the matching event's FeedbackValue so SDKs can verify their feedback loop end-to-end.

Released under MIT / Apache-2.0 License