* feat(cognito): implement managed login branding CreateManagedLoginBranding, DescribeManagedLoginBranding, DescribeManagedLoginBrandingByClient, UpdateManagedLoginBranding and DeleteManagedLoginBranding were unsupported, so a config declaring `aws_cognito_managed_login_branding` could not be applied against Floci. A branding belongs to one app client and is stored on it. Behaviour matches what the live API does: - a second branding for the same client raises ManagedLoginBrandingExistsException - ManagedLoginBrandingId must be a version 4 UUID, checked before the lookup - Settings is omitted from the response when the caller supplied none, while Assets is always returned - members an update omits are left unchanged Settings is stored opaquely rather than validated against AWS's unpublished schema, and ReturnMergedResources does not merge Cognito's default corpus. Closes #2856 * fix(cognito): reject malformed CreateManagedLoginBranding members Create coerced an absent UseCognitoProvidedValues to false and silently ignored a wrongly typed Settings or Assets, so a malformed request produced persisted state. Measured against AWS: neither UseCognitoProvidedValues nor Settings -> InvalidParameterException: useCognitoProvidedValues or settings should be specified (but not both) Assets of the wrong type -> SerializationException: Unexpected field type UseCognitoProvidedValues of the wrong type -> accepted, not rejected Create now enforces the first rule and type-checks Settings and Assets. A non-boolean UseCognitoProvidedValues is still accepted, because AWS accepts it. AWS answers a wrongly typed Settings with a 500 InternalErrorException; Floci returns the same client error it returns for Assets rather than reproducing that, and the divergence is documented. * fix(cognito): check Assets elements before converting them The Assets reader validated only the outer array, so a scalar element reached Jackson's convertValue and escaped as a 500 InternalFailure. This is the same class of bug as the LogConfigurations one, which I fixed in that reader without applying it here. AWS separates the two failures, and they differ from the LogConfigurations rules: [1, 2] / ["str"] -> SerializationException: Unexpected value type in payload [null] -> InvalidParameterException: 1 validation error detected: Value '[null]' at 'assets' failed to satisfy constraint: Member must satisfy constraint: [Member must not be null] A null element is rejected here, where LogConfigurations drops it. * fix(cognito): match AWS branding source validation A managed login branding request must select exactly one source of branding, and the same rule governs create and update. Measured against Cognito in ap-southeast-1: useCognitoProvidedValues settings result absent absent InvalidParameterException true absent accepted false absent InvalidParameterException absent present accepted true present InvalidParameterException false present accepted Create rejected only the neither case, update validated nothing at all, so naming both members and updating with no source both succeeded where the service rejects them. Presence of the member is not the test: false selects no source, which is why it needs settings alongside it. Reading the flag had to move with it. AWS coerces a JSON string rather than rejecting it, storing true for "true" and for "yes" and false for "false", while Jackson maps every string except "true" to false. That turned "yes" into a request selecting no source, so the coercion now follows the service. * fix(cognito): reject malformed UseCognitoProvidedValues types Jackson's asBoolean() maps a number, a JSON null, an object and an array all to false, so a malformed flag alongside valid Settings passed source validation and persisted as branding state that was never requested. Measured against Cognito in ap-southeast-1: 1, null, {} and [] are each a SerializationException, with or without Settings, while omitting the member is accepted and stores false. Only booleans and strings are read now, strings still coerced the way the service coerces them, and everything else raises SerializationException the way SesController already does. * fix(cognito): bound managed login branding assets at 40 Neither create nor update checked the documented 40-item maximum on Assets, so an oversized request was accepted and stored where AWS rejects it. Measured against Cognito in ap-southeast-1: create 40 assets passes the bound, reaches the source rule create 41 assets InvalidParameterException, length constraint create 41 + unknown client the length error, not the missing client update 41 + malformed id 2 validation errors, the length one first update malformed id alone 1 validation error, before the pool lookup The asset and branding-id checks now run before anything is looked up and share one message, matching those last three rows. DescribeManagedLoginBranding ran its pool lookup ahead of the branding-id check, which the fourth row shows is the wrong way round, so it moved with them. The length message embeds the request model's toString. The blob renders as the decoded buffer, confirmed at three payload sizes; the decoder used here is the lenient one so that building a rejection cannot itself fail.
17 KiB
Cognito
Protocol: JSON 1.1 (X-Amz-Target: AWSCognitoIdentityProviderService.*)
Endpoint: POST http://localhost:4566/
Floci serves pool-specific discovery and JWKS endpoints, plus a relaxed OAuth token endpoint, so local clients can mint and validate Cognito-like access tokens against RS256 signing keys.
CreateUserPool supports overiding several values using user-pool tags only at creation time:
floci:override-id, to pin the resultingUserPool.Id.floci:override-cognito-client-id- set to
use-nameto use the client name as client ID. - set to
append-to-name:-somestringto append a string to the client name to be used as client ID. - set to
prepend-to-name:somestring-to prepend a string to the client name to be used as client ID.
- set to
floci:override-cognito-client-secret, to set the secret for all clients created in this userpool.
Floci strips reserved floci:* tags from stored and returned UserPoolTags on both create and update paths, so the tag namespace acts as an input-only control channel and is never persisted as user-visible metadata.
Standalone TagResource rejects reserved floci:* keys. ListTagsForResource and UntagResource operate on the persisted user-pool tag map.
Supported Actions
User Pools
| Action | Description |
|---|---|
| CreateUserPool | Creates a local user pool, applying supported floci:* creation-time overrides from tags. |
| DescribeUserPool | Returns the stored user pool configuration. |
| ListUserPools | Lists local user pools visible in the request region. |
| UpdateUserPool | Updates mutable user pool settings and persisted user-pool tags. |
| DeleteUserPool | Deletes a local user pool and its related state. |
User Pool Tags
| Action | Description |
|---|---|
| TagResource | Adds user-visible tags to a user pool and rejects reserved floci:* tag keys. |
| UntagResource | Removes tags from a user pool's persisted tag map. |
| ListTagsForResource | Returns the persisted user-pool tags. |
User Pool Clients
| Action | Description |
|---|---|
| CreateUserPoolClient | Creates an app client for a user pool, including optional generated secret handling. |
| DescribeUserPoolClient | Returns the stored app client configuration. |
| ListUserPoolClients | Lists app clients for a user pool. |
| DeleteUserPoolClient | Deletes an app client from a user pool. |
Resource Servers
| Action | Description |
|---|---|
| CreateResourceServer | Registers a resource server and scopes for a user pool. |
| DescribeResourceServer | Returns a registered resource server. |
| ListResourceServers | Lists resource servers for a user pool. |
| UpdateResourceServer | Updates a resource server's name and scopes. |
| DeleteResourceServer | Deletes a resource server from a user pool. |
User Pool Domains
| Action | Description |
|---|---|
| CreateUserPoolDomain | Creates a Cognito prefix domain, or a custom domain when CustomDomainConfig.CertificateArn is given. |
| DescribeUserPoolDomain | Returns a domain's description, including CloudFrontDistribution for custom domains. |
| DeleteUserPoolDomain | Deletes a domain from its user pool. |
Log Delivery
| Action | Description |
|---|---|
| SetLogDeliveryConfiguration | Replaces a user pool's log delivery configuration. |
| GetLogDeliveryConfiguration | Returns a user pool's log delivery configuration. |
LogLevel accepts ERROR or INFO, and EventSource accepts userNotification or
userAuthEvents. LogConfigurations holds at most 2 entries, and an event source may
appear only once across them. Each entry must name a destination:
CloudWatchLogsConfiguration, FirehoseConfiguration or S3Configuration, and a request
that omits one is rejected the way AWS rejects it. Set replaces the whole list rather
than merging, so an empty LogConfigurations is what clears it, and Get always returns
the member, as [] when nothing is configured.
The length and enum checks run before the pool is looked up, so an oversized or malformed
request naming a pool that does not exist reports the request problem rather than
ResourceNotFoundException, and every violation of them is reported in one message.
Floci stores the configuration and never delivers anything to the destination: the log group, delivery stream or bucket is not written to, and is not required to exist. Two further divergences, both deliberate:
- No pricing-tier gate. AWS refuses
userAuthEventson a pool in theESSENTIALStier withFeatureUnavailableInTierException; Floci accepts either event source whateverUserPoolTiersays. - No destination validation. AWS checks the ARN it is handed; Floci stores it as given.
Admin User Management
| Action | Description |
|---|---|
| AdminCreateUser | Creates or resends setup for a user in a user pool. |
| AdminGetUser | Returns a user's stored attributes and status. |
| AdminDeleteUser | Deletes a user from a user pool. |
| AdminSetUserPassword | Sets a user's password and permanent-password status. |
| AdminUpdateUserAttributes | Updates attributes for a user in a user pool. |
| AdminLinkProviderForUser | Links an external IdP identity to an existing user's identities attribute. |
User Operations
| Action | Description |
|---|---|
| SignUp | Creates a self-service user for an app client. |
| ConfirmSignUp | Confirms a pending self-service signup. |
| GetUser | Returns attributes for the authenticated access-token user. |
| GetUserAttributeVerificationCode | Issues a verification code for the authenticated user's email or phone_number attribute. |
| UpdateUserAttributes | Updates attributes for the authenticated access-token user. |
| ChangePassword | Changes the authenticated user's password. |
| ForgotPassword | Starts the local forgot-password flow for a user. |
| ConfirmForgotPassword | Completes the forgot-password flow by setting a replacement password. |
Authentication
| Action | Description |
|---|---|
| InitiateAuth | Authenticates app-client users through supported user-password and SRP-style flows. |
| AdminInitiateAuth | Starts an admin authentication flow for a user pool user. |
| RespondToAuthChallenge | Responds to supported Cognito auth challenges. |
User Listing
| Action | Description |
|---|---|
| ListUsers | Lists users stored in a user pool. |
Groups
| Action | Description |
|---|---|
| CreateGroup | Creates a group in a user pool. |
| GetGroup | Returns a user-pool group. |
| UpdateGroup | Updates a user-pool group's stored settings. |
| ListGroups | Lists groups in a user pool. |
| ListUsersInGroup | Lists users assigned to a group. |
| DeleteGroup | Deletes a group from a user pool. |
| AdminAddUserToGroup | Adds a user to a group. |
| AdminRemoveUserFromGroup | Removes a user from a group. |
| AdminListGroupsForUser | Lists the groups assigned to a user. |
Managed Login Branding
| Action | Description |
|---|---|
| CreateManagedLoginBranding | Creates the branding for an app client. |
| DescribeManagedLoginBranding | Returns a branding by its id. |
| DescribeManagedLoginBrandingByClient | Returns the branding attached to an app client. |
| UpdateManagedLoginBranding | Updates a branding's settings, assets or provided-values flag. |
| DeleteManagedLoginBranding | Deletes a branding from its app client. |
CreateManagedLoginBranding must name either UseCognitoProvidedValues or Settings; a
request with neither is rejected. One branding per app client: a second
CreateManagedLoginBranding for the same client is rejected with
ManagedLoginBrandingExistsException. ManagedLoginBrandingId must be a
version 4 UUID, and a malformed one is rejected before the lookup, as AWS does.
Assets holds at most 40 entries on create and on update.
Settings is omitted from the response when the caller supplied none, while Assets is
always returned. Members an update omits are left unchanged.
The asset-count and branding-id checks run before the pool, client or branding is looked
up, so an oversized request naming something that does not exist reports the request
problem rather than ResourceNotFoundException, and an update violating both reports them
in one message with the asset list first.
Branding is presentation for the hosted UI, which Floci does not serve, so it is stored and returned rather than rendered. Two divergences follow from that:
Settingsis stored opaquely. AWS validates it against a deep schema, rejecting unknown properties withInvalid settings provided. Validation errors: [{property: $.components...., errorType: UnknownProperty}]. That schema is not published, so Floci accepts any object.- A wrongly typed
Settingsreturns a client error. AWS answers that particular input withInternalErrorExceptionand a 500; Floci returnsSerializationException: Unexpected field type, which is what AWS returns for a wrongly typedAssets. Reproducing someone else's 500 seemed worse than being consistent. ReturnMergedResourcesis not honoured. Against AWS it merges Cognito's own default settings and assets into the response: on a pool with 8 configured assets it returns 38. Reproducing that needs Cognito's default corpus, so Floci returns the stored branding either way.
Well-Known And OAuth Endpoints
| Endpoint | Description |
|---|---|
GET /{userPoolId}/.well-known/openid-configuration |
OpenID discovery document |
GET /{userPoolId}/.well-known/jwks.json |
JSON Web Key Set for JWT validation |
POST /cognito-idp/oauth2/token |
Relaxed OAuth token endpoint for grant_type=client_credentials |
POST /cognito-idp/oauth2/token is intentionally emulator-friendly rather than full Cognito parity:
- It requires an existing
client_id. - It accepts
client_idandclient_secretfrom the form body or Basic auth. - It requires a confidential app client created with
GenerateSecret=true. - It requires
AllowedOAuthFlowsUserPoolClient=trueandAllowedOAuthFlows=["client_credentials"]. - It doesn't require a Cognito domain.
- It returns only
access_token,token_type, andexpires_in. - It validates requested OAuth scopes against the app client's
AllowedOAuthScopesand the pool's registered resource-server scopes. - It advertises the prefixed token endpoint in
/{userPoolId}/.well-known/openid-configuration.
Sign-in Identifiers (UsernameAttributes)
Floci follows real Cognito semantics for pools created with UsernameAttributes (e.g.
--username-attributes email):
AdminCreateUser/SignUpaccept the email (or phone number) as the sign-in value, but the canonicalUsernameis an auto-generated, immutable UUID equal tosub. The supplied email is stored as a mutable alias attribute.ListUsers,AdminGetUserand Lambda triggerevent.userNameall report the UUID, never the email; the email lives in theemailattribute and inevent.request.userAttributes.email.- Sign-in resolves by the current email alias or the UUID.
SECRET_HASHis validated against the exactUSERNAMEvalue sent:Base64(HMAC-SHA256(USERNAME + clientId, clientSecret)). - In
CUSTOM_AUTH/ SRP flows,ChallengeParameters.USERNAMEechoes the UUID (as real AWS does); theRespondToAuthChallengeSECRET_HASHis validated against theUSERNAMEsent that round. ThatUSERNAMEmust still resolve to the session's user — the UUID or any of its current aliases — and a value naming a different user is rejected withNotAuthorizedException. AdminUpdateUserAttributescan change the email; afterwards sign-in works with the new email and fails with the old one, whileUsername/substay fixed.- Duplicate email/phone on
AdminCreateUser:UsernameExistsExceptionwhen the incoming alias is unverified,AliasExistsExceptionwhen it is verified (email_verified=true); passForceAliasCreation=trueto migrate a verified alias off the previous owner. OnAdminUpdateUserAttributes, changing to an in-use alias throwsAliasExistsException.
Pools without UsernameAttributes (classic pools, and pools using AliasAttributes) keep the
literal Username you supply, unchanged.
Token claims
Floci mirrors AWS's access-token / ID-token split:
- Access token:
sub,username(the UUID),scope(aws.cognito.signin.user.adminfor API sign-in),client_id,cognito:groups,jti/origin_jti. It does not carrycognito:usernameor user attributes likeemail. - ID token:
sub,cognito:username,aud, and readable user attributes (email,email_verified,phone_number,custom:*, ...). Attribute claims are filtered by the app client'sReadAttributes(an unset/empty list means all attributes are readable).
Not-found errors (ResourceNotFoundException, UserNotFoundException) return HTTP 400, matching the
Cognito JSON protocol.
Configuration
| Variable | Default | Description |
|---|---|---|
FLOCI_SERVICES_COGNITO_ENABLED |
true |
Enable or disable the service |
Examples
export AWS_ENDPOINT_URL=http://localhost:4566
# Create a user pool
POOL_ID=$(aws cognito-idp create-user-pool \
--pool-name MyApp \
--query UserPool.Id --output text \
--endpoint-url $AWS_ENDPOINT_URL)
# Create an app client
CLIENT_ID=$(aws cognito-idp create-user-pool-client \
--user-pool-id $POOL_ID \
--client-name my-client \
--generate-secret \
--allowed-o-auth-flows-user-pool-client \
--allowed-o-auth-flows client_credentials \
--allowed-o-auth-scopes notes/read notes/write \
--query UserPoolClient.ClientId --output text \
--endpoint-url $AWS_ENDPOINT_URL)
# Retrieve the generated client secret
CLIENT_SECRET=$(aws cognito-idp describe-user-pool-client \
--user-pool-id $POOL_ID \
--client-id $CLIENT_ID \
--query UserPoolClient.ClientSecret --output text \
--endpoint-url $AWS_ENDPOINT_URL)
# Register a resource server and scopes
aws cognito-idp create-resource-server \
--user-pool-id $POOL_ID \
--identifier notes \
--name "Notes API" \
--scopes ScopeName=read,ScopeDescription="Read notes" ScopeName=write,ScopeDescription="Write notes" \
--endpoint-url $AWS_ENDPOINT_URL
# Create a user
aws cognito-idp admin-create-user \
--user-pool-id $POOL_ID \
--username alice@example.com \
--temporary-password Temp1234! \
--endpoint-url $AWS_ENDPOINT_URL
# Set a permanent password
aws cognito-idp admin-set-user-password \
--user-pool-id $POOL_ID \
--username alice@example.com \
--password Perm1234! \
--permanent \
--endpoint-url $AWS_ENDPOINT_URL
# Authenticate
aws cognito-idp initiate-auth \
--auth-flow USER_PASSWORD_AUTH \
--client-id $CLIENT_ID \
--auth-parameters USERNAME=alice@example.com,PASSWORD=Perm1234! \
--endpoint-url $AWS_ENDPOINT_URL
# Create a group
aws cognito-idp create-group \
--user-pool-id $POOL_ID \
--group-name admin \
--description "Admin group" \
--endpoint-url $AWS_ENDPOINT_URL
# Add user to group
aws cognito-idp admin-add-user-to-group \
--user-pool-id $POOL_ID \
--group-name admin \
--username alice@example.com \
--endpoint-url $AWS_ENDPOINT_URL
# List groups for user
aws cognito-idp admin-list-groups-for-user \
--user-pool-id $POOL_ID \
--username alice@example.com \
--endpoint-url $AWS_ENDPOINT_URL
# Fetch the pool discovery document
curl -s "$AWS_ENDPOINT_URL/$POOL_ID/.well-known/openid-configuration"
# Get a machine access token from the OAuth endpoint
curl -s \
-X POST "$AWS_ENDPOINT_URL/cognito-idp/oauth2/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-u "$CLIENT_ID:$CLIENT_SECRET" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "scope=notes/read notes/write"
JWT Validation
Tokens issued by Floci can be validated using the discovery and JWKS endpoints:
http://localhost:4566/$POOL_ID/.well-known/openid-configuration
http://localhost:4566/$POOL_ID/.well-known/jwks.json
Tokens include the cognito:groups claim as a JSON array when the authenticated user belongs to one or more groups.
Tokens issued by Cognito auth flows and the OAuth token endpoint use the emulator base URL plus the pool id:
http://localhost:4566/$POOL_ID
This keeps the issuer, discovery document, JWKS URL, and token endpoint internally consistent for local JWT validation while supporting LocalStack-style confidential clients and resource-server-backed scopes.