Skip to content

confirm_sign_up async

confirm_sign_up(
    client_id: ClientIdType,
    username: UsernameType,
    confirmation_code: ConfirmationCodeType,
    *,
    config_overrides: Optional[AsyncCognitoIdentityProviderClientConfig] = None,
    secret_hash: Optional[SecretHashType] = None,
    force_alias_creation: Optional[ForceAliasCreation] = None,
    analytics_metadata: Optional[AnalyticsMetadataType] = None,
    user_context_data: Optional[UserContextDataType] = None,
    client_metadata: Optional[ClientMetadataType] = None,
    session: Optional[SessionType] = None,
) -> ConfirmSignUpResponse

Confirms the account of a new user. This public API operation submits a code that Amazon Cognito sent to your user when they signed up in your user pool. After your user enters their code, they confirm ownership of the email address or phone number that they provided, and their user account becomes active. Depending on your user pool configuration, your users will receive their confirmation code in an email or SMS message.

Local users who signed up in your user pool are the only type of user who can confirm sign-up with a code. Users who federate through an external identity provider (IdP) have already been confirmed by their IdP.

Amazon Cognito doesn't evaluate Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you can't use IAM credentials to authorize requests, and you can't grant IAM permissions in policies. For more information about authorization models in Amazon Cognito, see Using the Amazon Cognito user pools API and user pool endpoints.

Parameters:

  • client_id (ClientIdType) –

    The ID of the app client associated with the user pool.

  • secret_hash (Optional[SecretHashType], default: None ) –

    A keyed-hash message authentication code (HMAC) calculated using the secret key of a user pool client and username plus the client ID in the message. For more information about SecretHash, see Computing secret hash values.

  • username (UsernameType) –

    The name of the user that you want to query or modify. The value of this parameter is typically your user's username, but it can be any of their alias attributes. If username isn't an alias attribute in your user pool, this value must be the sub of a local user or the username of a user from a third-party IdP.

  • confirmation_code (ConfirmationCodeType) –

    The confirmation code that your user pool sent in response to the SignUp request.

  • force_alias_creation (Optional[ForceAliasCreation], default: None ) –

    When true, forces user confirmation despite any existing aliases. Defaults to false. A value of true migrates the alias from an existing user to the new user if an existing user already has the phone number or email address as an alias.

    Say, for example, that an existing user has an email attribute of [email protected] and email is an alias in your user pool. If the new user also has an email of [email protected] and your ConfirmSignUp response sets ForceAliasCreation to true, the new user can sign in with a username of [email protected] and the existing user can no longer do so.

    If false and an attribute belongs to an existing alias, this request returns an AliasExistsException error.

    For more information about sign-in aliases, see Customizing sign-in attributes.

  • analytics_metadata (Optional[AnalyticsMetadataType], default: None ) –

    Information that supports analytics outcomes with Amazon Pinpoint, including the user's endpoint ID. The endpoint ID is a destination for Amazon Pinpoint push notifications, for example a device identifier, email address, or phone number.

  • user_context_data (Optional[UserContextDataType], default: None ) –

    Contextual data about your user session like the device fingerprint, IP address, or location. Amazon Cognito threat protection evaluates the risk of an authentication event based on the context that your app generates and passes to Amazon Cognito when it makes API requests.

    For more information, see Collecting data for threat protection in applications.

  • client_metadata (Optional[ClientMetadataType], default: None ) –

    A map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers. You create custom workflows by assigning Lambda functions to user pool triggers.

    When Amazon Cognito invokes any of these functions, it passes a JSON payload, which the function receives as input. This payload contains a clientMetadata attribute that provides the data that you assigned to the ClientMetadata parameter in your request. In your function code, you can process the clientMetadata value to enhance your workflow for your specific needs.

    To review the Lambda trigger types that Amazon Cognito invokes at runtime with API requests, see Connecting API actions to Lambda triggers in the Amazon Cognito Developer Guide.

    When you use the ClientMetadata parameter, note that Amazon Cognito won't do the following:

    • Store the ClientMetadata value. This data is available only to Lambda triggers that are assigned to a user pool to support custom workflows. If your user pool configuration doesn't include triggers, the ClientMetadata parameter serves no purpose.

    • Validate the ClientMetadata value.

    • Encrypt the ClientMetadata value. Don't send sensitive information in this parameter.

  • session (Optional[SessionType], default: None ) –

    The optional session ID from a SignUp API request. You can sign in a user directly from the sign-up process with the USER_AUTH authentication flow.

Raises:

  • AliasExistsException –

    This exception is thrown when a user tries to confirm the account with an email address or phone number that has already been supplied as an alias for a different user profile. This exception indicates that an account with this email address or phone already exists in a user pool that you've configured to use email address or phone number as a sign-in alias.

  • CodeMismatchException –

    This exception is thrown if the provided code doesn't match what the server was expecting.

  • ExpiredCodeException –

    This exception is thrown if a code has expired.

  • ForbiddenException –

    This exception is thrown when WAF doesn't allow your request based on a web ACL that's associated with your user pool.

  • InternalErrorException –

    This exception is thrown when Amazon Cognito encounters an internal error.

  • InvalidLambdaResponseException –

    This exception is thrown when Amazon Cognito encounters an invalid Lambda response.

  • InvalidParameterException –

    This exception is thrown when the Amazon Cognito service encounters an invalid parameter.

  • LimitExceededException –

    This exception is thrown when a user exceeds the limit for a requested Amazon Web Services resource.

  • NotAuthorizedException –

    This exception is thrown when a user isn't authorized.

  • OperationNotEnabledException –

    This exception is thrown when an operation is not available in the current region or for the current user pool configuration. This can occur when attempting to perform operations that are not supported in secondary replica regions.

  • ResourceNotFoundException –

    This exception is thrown when the Amazon Cognito service can't find the requested resource.

  • TooManyFailedAttemptsException –

    This exception is thrown when the user has made too many failed attempts for a given action, such as sign-in.

  • TooManyRequestsException –

    This exception is thrown when the user has made too many requests for a given operation.

  • UnexpectedLambdaException –

    This exception is thrown when Amazon Cognito encounters an unexpected exception with Lambda.

  • UserLambdaValidationException –

    This exception is thrown when the Amazon Cognito service encounters a user validation exception with the Lambda service.

  • UserNotFoundException –

    This exception is thrown when a user isn't found.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_cognito_identity_provider/_services/async_cognito_identity_provider.py
async def confirm_sign_up(
    self,
    client_id: "capo_cognito_identity_provider.types.client_id_type.ClientIdType",
    username: "capo_cognito_identity_provider.types.username_type.UsernameType",
    confirmation_code: "capo_cognito_identity_provider.types.confirmation_code_type.ConfirmationCodeType",
    *,
    config_overrides: Optional[AsyncCognitoIdentityProviderClientConfig] = None,
    secret_hash: Optional[
        "capo_cognito_identity_provider.types.secret_hash_type.SecretHashType"
    ] = None,
    force_alias_creation: Optional[
        "capo_cognito_identity_provider.types.force_alias_creation.ForceAliasCreation"
    ] = None,
    analytics_metadata: Optional[
        "capo_cognito_identity_provider.types.analytics_metadata_type.AnalyticsMetadataType"
    ] = None,
    user_context_data: Optional[
        "capo_cognito_identity_provider.types.user_context_data_type.UserContextDataType"
    ] = None,
    client_metadata: Optional[
        "capo_cognito_identity_provider.types.client_metadata_type.ClientMetadataType"
    ] = None,
    session: Optional[
        "capo_cognito_identity_provider.types.session_type.SessionType"
    ] = None,
) -> "capo_cognito_identity_provider.types.confirm_sign_up_response.ConfirmSignUpResponse":
    """<p>Confirms the account of a new user. This public API operation submits a code that Amazon Cognito sent to your user when they signed up in your user pool. After your user enters their code, they confirm ownership of the email address or phone number that they provided, and their user account becomes active. Depending on your user pool configuration, your users will receive their confirmation code in an email or SMS message.</p> <p>Local users who signed up in your user pool are the only type of user who can confirm sign-up with a code. Users who federate through an external identity provider (IdP) have already been confirmed by their IdP.</p> <note> <p>Amazon Cognito doesn't evaluate Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you can't use IAM credentials to authorize requests, and you can't grant IAM permissions in policies. For more information about authorization models in Amazon Cognito, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pools-API-operations.html">Using the Amazon Cognito user pools API and user pool endpoints</a>.</p> </note>

    Args:
        client_id: <p>The ID of the app client associated with the user pool.</p>
        secret_hash: <p>A keyed-hash message authentication code (HMAC) calculated using the secret key of a user pool client and username plus the client ID in the message. For more information about <code>SecretHash</code>, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/signing-up-users-in-your-app.html#cognito-user-pools-computing-secret-hash">Computing secret hash values</a>.</p>
        username: <p>The name of the user that you want to query or modify. The value of this parameter is typically your user's username, but it can be any of their alias attributes. If <code>username</code> isn't an alias attribute in your user pool, this value must be the <code>sub</code> of a local user or the username of a user from a third-party IdP.</p>
        confirmation_code: <p>The confirmation code that your user pool sent in response to the <code>SignUp</code> request.</p>
        force_alias_creation: <p>When <code>true</code>, forces user confirmation despite any existing aliases. Defaults to <code>false</code>. A value of <code>true</code> migrates the alias from an existing user to the new user if an existing user already has the phone number or email address as an alias.</p> <p>Say, for example, that an existing user has an <code>email</code> attribute of <code>[email protected]</code> and email is an alias in your user pool. If the new user also has an email of <code>[email protected]</code> and your <code>ConfirmSignUp</code> response sets <code>ForceAliasCreation</code> to <code>true</code>, the new user can sign in with a username of <code>[email protected]</code> and the existing user can no longer do so.</p> <p>If <code>false</code> and an attribute belongs to an existing alias, this request returns an <b>AliasExistsException</b> error.</p> <p>For more information about sign-in aliases, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-aliases">Customizing sign-in attributes</a>.</p>
        analytics_metadata: <p>Information that supports analytics outcomes with Amazon Pinpoint, including the user's endpoint ID. The endpoint ID is a destination for Amazon Pinpoint push notifications, for example a device identifier, email address, or phone number.</p>
        user_context_data: <p>Contextual data about your user session like the device fingerprint, IP address, or location. Amazon Cognito threat protection evaluates the risk of an authentication event based on the context that your app generates and passes to Amazon Cognito when it makes API requests.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-viewing-threat-protection-app.html">Collecting data for threat protection in applications</a>.</p>
        client_metadata: <p>A map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers. You create custom workflows by assigning Lambda functions to user pool triggers.</p> <p>When Amazon Cognito invokes any of these functions, it passes a JSON payload, which the function receives as input. This payload contains a <code>clientMetadata</code> attribute that provides the data that you assigned to the ClientMetadata parameter in your request. In your function code, you can process the <code>clientMetadata</code> value to enhance your workflow for your specific needs.</p> <p>To review the Lambda trigger types that Amazon Cognito invokes at runtime with API requests, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-working-with-lambda-triggers.html#lambda-triggers-by-event"> Connecting API actions to Lambda triggers</a> in the <i>Amazon Cognito Developer Guide</i>.</p> <note> <p>When you use the <code>ClientMetadata</code> parameter, note that Amazon Cognito won't do the following:</p> <ul> <li> <p>Store the <code>ClientMetadata</code> value. This data is available only to Lambda triggers that are assigned to a user pool to support custom workflows. If your user pool configuration doesn't include triggers, the <code>ClientMetadata</code> parameter serves no purpose.</p> </li> <li> <p>Validate the <code>ClientMetadata</code> value.</p> </li> <li> <p>Encrypt the <code>ClientMetadata</code> value. Don't send sensitive information in this parameter.</p> </li> </ul> </note>
        session: <p>The optional session ID from a <code>SignUp</code> API request. You can sign in a user directly from the sign-up process with the <code>USER_AUTH</code> authentication flow.</p>

    Raises:
        capo_cognito_identity_provider.errors.alias_exists_exception.AliasExistsException: <p>This exception is thrown when a user tries to confirm the account with an email address or phone number that has already been supplied as an alias for a different user profile. This exception indicates that an account with this email address or phone already exists in a user pool that you've configured to use email address or phone number as a sign-in alias.</p>
        capo_cognito_identity_provider.errors.code_mismatch_exception.CodeMismatchException: <p>This exception is thrown if the provided code doesn't match what the server was expecting.</p>
        capo_cognito_identity_provider.errors.expired_code_exception.ExpiredCodeException: <p>This exception is thrown if a code has expired.</p>
        capo_cognito_identity_provider.errors.forbidden_exception.ForbiddenException: <p>This exception is thrown when WAF doesn't allow your request based on a web ACL that's associated with your user pool.</p>
        capo_cognito_identity_provider.errors.internal_error_exception.InternalErrorException: <p>This exception is thrown when Amazon Cognito encounters an internal error.</p>
        capo_cognito_identity_provider.errors.invalid_lambda_response_exception.InvalidLambdaResponseException: <p>This exception is thrown when Amazon Cognito encounters an invalid Lambda response.</p>
        capo_cognito_identity_provider.errors.invalid_parameter_exception.InvalidParameterException: <p>This exception is thrown when the Amazon Cognito service encounters an invalid parameter.</p>
        capo_cognito_identity_provider.errors.limit_exceeded_exception.LimitExceededException: <p>This exception is thrown when a user exceeds the limit for a requested Amazon Web Services resource.</p>
        capo_cognito_identity_provider.errors.not_authorized_exception.NotAuthorizedException: <p>This exception is thrown when a user isn't authorized.</p>
        capo_cognito_identity_provider.errors.operation_not_enabled_exception.OperationNotEnabledException: <p>This exception is thrown when an operation is not available in the current region or for the current user pool configuration. This can occur when attempting to perform operations that are not supported in secondary replica regions.</p>
        capo_cognito_identity_provider.errors.resource_not_found_exception.ResourceNotFoundException: <p>This exception is thrown when the Amazon Cognito service can't find the requested resource.</p>
        capo_cognito_identity_provider.errors.too_many_failed_attempts_exception.TooManyFailedAttemptsException: <p>This exception is thrown when the user has made too many failed attempts for a given action, such as sign-in.</p>
        capo_cognito_identity_provider.errors.too_many_requests_exception.TooManyRequestsException: <p>This exception is thrown when the user has made too many requests for a given operation.</p>
        capo_cognito_identity_provider.errors.unexpected_lambda_exception.UnexpectedLambdaException: <p>This exception is thrown when Amazon Cognito encounters an unexpected exception with Lambda.</p>
        capo_cognito_identity_provider.errors.user_lambda_validation_exception.UserLambdaValidationException: <p>This exception is thrown when the Amazon Cognito service encounters a user validation exception with the Lambda service.</p>
        capo_cognito_identity_provider.errors.user_not_found_exception.UserNotFoundException: <p>This exception is thrown when a user isn't found.</p>
        capo_cognito_identity_provider.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_cognito_identity_provider.types.confirm_sign_up_request.ConfirmSignUpRequest]",
    ) -> AsyncOperationResponse[
        "capo_cognito_identity_provider.types.confirm_sign_up_response.ConfirmSignUpResponse"
    ]:
        import capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.confirm_sign_up

        (
            output,
            http_response,
        ) = await capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.confirm_sign_up.async_confirm_sign_up(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_cognito_identity_provider.types.confirm_sign_up_request.ConfirmSignUpRequest",
    ) -> dict[str, Any]:
        import capo_cognito_identity_provider.types.confirm_sign_up_request

        return capo_cognito_identity_provider.types.confirm_sign_up_request.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_cognito_identity_provider.types.confirm_sign_up_response.ConfirmSignUpResponse",
    ) -> dict[str, Any]:
        import capo_cognito_identity_provider.types.confirm_sign_up_response

        return capo_cognito_identity_provider.types.confirm_sign_up_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "ConfirmSignUp",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_cognito_identity_provider.types.confirm_sign_up_request.ConfirmSignUpRequest = {
        "client_id": client_id,
        "username": username,
        "confirmation_code": confirmation_code,
    }
    if secret_hash is not None:
        input_["secret_hash"] = secret_hash
    if force_alias_creation is not None:
        input_["force_alias_creation"] = force_alias_creation
    if analytics_metadata is not None:
        input_["analytics_metadata"] = analytics_metadata
    if user_context_data is not None:
        input_["user_context_data"] = user_context_data
    if client_metadata is not None:
        input_["client_metadata"] = client_metadata
    if session is not None:
        input_["session"] = session

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output