Amazon Cognito app client secrets can now be managed with AWS Secrets Manager, so I tried it out

Amazon Cognito app client secrets can now be managed with AWS Secrets Manager, so I tried it out

Amazon Cognito app client secrets can now be managed in AWS Secrets Manager. Using the AWS CLI, I confirmed that enabling it on a new app client returns ClientSecretArn and that the secret retrieved from Secrets Manager authenticates.
2026.11.20

This page has been translated by machine translation. View original

Introduction

On November 19, 2026, it was announced that Amazon Cognito app client secrets can now be stored and managed in AWS Secrets Manager.

https://aws.amazon.com/about-aws/whats-new/2026/11/cognito-secrets-manager-integration/

In this article, I try the following with the AWS CLI: enabling Secrets Manager management on a new app client, retrieving the stored value, and authenticating with that value.

Test Environment

  • Region: ap-northeast-1
  • AWS CLI: 2.41.2
  • User pool: newly created for testing

The following commands are run in a shell with this environment variable set.

export AWS_REGION=ap-northeast-1

Creating an App Client

An app client secret is a secret value that an app running on the server side uses to identify itself to Cognito, and it is used to calculate the SECRET_HASH included in API requests. To enable it on a new app client, add --publish-secrets-in-aws-secrets-manager to create-user-pool-client. What is stored in Secrets Manager is the secret generated by Cognito, so use it together with --generate-secret. --explicit-auth-flows is specified so that USER_PASSWORD_AUTH can be used in the authentication described later.

aws cognito-idp create-user-pool-client \
  --user-pool-id <ユーザープールID> \
  --client-name verify-managed-secret \
  --generate-secret \
  --publish-secrets-in-aws-secrets-manager \
  --explicit-auth-flows ALLOW_USER_PASSWORD_AUTH ALLOW_REFRESH_TOKEN_AUTH \
  --output json

The response contained ClientSecretArn instead of ClientSecret.

{
    "UserPoolClient": {
        "UserPoolId": "ap-northeast-1_EXAMPLE",
        "ClientName": "verify-managed-secret",
        "ClientId": "1example23456789",
        "ClientSecretArn": "arn:aws:secretsmanager:ap-northeast-1:123456789012:secret:cognito-idp!1example23456789-AbCdEf",
        "LastModifiedDate": "2026-11-20T09:58:52.732000+09:00",
        "CreationDate": "2026-11-20T09:58:51.833000+09:00",
        "RefreshTokenValidity": 30,
        "TokenValidityUnits": {},
        "ExplicitAuthFlows": [
            "ALLOW_USER_PASSWORD_AUTH",
            "ALLOW_REFRESH_TOKEN_AUTH"
        ],
        "AllowedOAuthFlowsUserPoolClient": false,
        "EnableTokenRevocation": true,
        "EnablePropagateAdditionalUserContextData": false,
        "AuthSessionValidity": 3,
        "ClientType": "REGULAR"
    }
}

Even when I ran describe-user-pool-client after creation, the response did not contain ClientSecret, and ClientSecretArn was returned.

For comparison, I created an app client with only --generate-secret, without --publish-secrets-in-aws-secrets-manager. In this case, the responses of both create-user-pool-client and describe-user-pool-client contained the plaintext ClientSecret and did not contain ClientSecretArn. The following is the beginning of the create-user-pool-client response. The ClientSecret value is hidden.

{
    "UserPoolClient": {
        "UserPoolId": "ap-northeast-1_EXAMPLE",
        "ClientName": "verify-unmanaged-secret",
        "ClientId": "1example23456789",
        "ClientSecret": "<マスク済み>",
        ...
    }
}

I confirmed that the service-linked role AWSServiceRoleForAmazonCognitoIdp was automatically created in the account immediately after the app client was created.

Retrieving the Secret Value

You can retrieve the secret value by passing the ClientSecretArn to --secret-id of get-secret-value. Because the ! in the ARN is subject to shell history expansion, enclose it in single quotes.

aws secretsmanager get-secret-value --secret-id '<ClientSecretArn>' --output json

SecretString is in JSON format, and the secret itself is stored under the clientSecretValue key. In the following response, the actual value of clientSecretValue has been replaced with <MASKED>.

{
  "ARN": "arn:aws:secretsmanager:ap-northeast-1:123456789012:secret:cognito-idp!1example23456789-AbCdEf",
  "Name": "cognito-idp!1example23456789",
  "VersionId": "EXAMPLE1-90ab-cdef-fedc-ba987EXAMPLE",
  "SecretString": "{\"userPoolClientId\":\"1example23456789\",\"userPoolId\":\"ap-northeast-1_EXAMPLE\",\"clientSecretValue\":\"<MASKED>\"}",
  "VersionStages": [
    "AWSCURRENT"
  ],
  "CreatedDate": "2026-11-20T09:58:52.550000+09:00"
}

Authenticating with the Retrieved Value

To authenticate with an app client that has a secret, you need to pass SECRET_HASH. SECRET_HASH is the Base64-encoded value of the HMAC-SHA256 calculated over the string formed by concatenating the username and the client ID, using clientSecretValue as the key.

https://docs.aws.amazon.com/cognito/latest/developerguide/signing-up-users-in-your-app.html

To verify authentication, I use a test user whose password is already confirmed. The commands to create it are as follows.

Creating a test user
export POOL=<ユーザープールID>
export TESTUSER=<テストユーザー名>
export TESTPW=<テストユーザーのパスワード>

aws cognito-idp admin-create-user --user-pool-id $POOL --username $TESTUSER --message-action SUPPRESS --output json
aws cognito-idp admin-set-user-password --user-pool-id $POOL --username $TESTUSER --password "$TESTPW" --permanent

Save the following script as auth-with-managed-secret.sh. The jq at the end replaces the tokens in the output with <MASKED>.

#!/usr/bin/env bash
# Retrieve clientSecretValue from Secrets Manager, calculate SECRET_HASH, and run initiate-auth
# Required environment variables: SECRET_ARN, CID, TESTUSER, TESTPW, AWS_REGION
set -euo pipefail
SECRET=$(aws secretsmanager get-secret-value --secret-id "$SECRET_ARN" --query SecretString --output text | jq -r .clientSecretValue)
SECRET_HASH=$(printf '%s' "${TESTUSER}${CID}" | openssl dgst -sha256 -hmac "$SECRET" -binary | base64)
aws cognito-idp initiate-auth \
  --client-id "$CID" \
  --auth-flow USER_PASSWORD_AUTH \
  --auth-parameters "USERNAME=$TESTUSER,PASSWORD=$TESTPW,SECRET_HASH=$SECRET_HASH" \
  --output json \
  | jq '.AuthenticationResult |= with_entries(if .key|test("Token$") then .value="<MASKED>" else . end)'

In addition to TESTUSER and TESTPW set when creating the test user and AWS_REGION set in the test environment, set SECRET_ARN and CID, and then run the script.

export SECRET_ARN='<ClientSecretArn>'
export CID=<クライアントID>

bash auth-with-managed-secret.sh

The response contained AuthenticationResult. The SECRET_HASH calculated with the value retrieved from Secrets Manager was accepted, and I was able to authenticate as the test user.

{
  "ChallengeParameters": {},
  "AuthenticationResult": {
    "AccessToken": "<MASKED>",
    "ExpiresIn": 3600,
    "TokenType": "Bearer",
    "RefreshToken": "<MASKED>",
    "IdToken": "<MASKED>"
  }
}

Summary

Amazon Cognito app client secrets can now be managed in AWS Secrets Manager.

Previously, API responses contained the plaintext ClientSecret. With an app client enabled through this update, the response returns ClientSecretArn, and I confirmed that authenticating the test user succeeds with the SECRET_HASH calculated from the value retrieved from Secrets Manager.

Secrets Manager pricing is charged separately, but if you want to reduce the risk of exposing app client secrets, give this update a try.

Share this article

AWSのお困り事はクラスメソッドへ