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\":\"alice@example.com\",\"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\":\"alice@example.com\",\"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\":\"alice@example.com\",\"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.

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: 'alice@example.com',
  TemporaryPassword: 'Temp@123!',
}));
await cognito.send(new AdminSetUserPasswordCommand({
  UserPoolId: userPoolId,
  Username: 'alice@example.com',
  Password: 'MyPassword123!',
  Permanent: true,
}));

// Sign in
const { AuthenticationResult } = await cognito.send(new InitiateAuthCommand({
  AuthFlow: 'USER_PASSWORD_AUTH',
  ClientId: clientId,
  AuthParameters: {
    USERNAME: 'alice@example.com',
    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.
  • Advanced security features (adaptive authentication, risk scoring) are stubs.
  • Identity pool credentials are valid for testing SDK calls — they use the AWSim account.

Released under MIT / Apache-2.0 License