Skip to content

initiate_auth

initiate_auth(
    auth_flow: AuthFlowType,
    client_id: ClientIdType,
    *,
    config_overrides: Optional[CognitoIdentityProviderClientConfig] = None,
    auth_parameters: Optional[AuthParametersType] = None,
    client_metadata: Optional[ClientMetadataType] = None,
    analytics_metadata: Optional[AnalyticsMetadataType] = None,
    user_context_data: Optional[UserContextDataType] = None,
    session: Optional[SessionType] = None,
) -> InitiateAuthResponse

Declares an authentication flow and initiates sign-in for a user in the Amazon Cognito user directory. Amazon Cognito might respond with an additional challenge or an AuthenticationResult that contains the outcome of a successful authentication. You can't sign in a user with a federated IdP with InitiateAuth. For more information, see Authentication.

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.

This action might generate an SMS text message. Starting June 1, 2021, US telecom carriers require you to register an origination phone number before you can send SMS messages to US phone numbers. If you use SMS text messages in Amazon Cognito, you must register a phone number with Amazon Pinpoint. Amazon Cognito uses the registered number automatically. Otherwise, Amazon Cognito users who must receive SMS messages might not be able to sign up, activate their accounts, or sign in.

If you have never used SMS text messages with Amazon Cognito or any other Amazon Web Services service, Amazon Simple Notification Service might place your account in the SMS sandbox. In sandbox mode , you can send messages only to verified phone numbers. After you test your app while in the sandbox environment, you can move out of the sandbox and into production. For more information, see SMS message settings for Amazon Cognito user pools in the Amazon Cognito Developer Guide.

Parameters:

  • auth_flow (AuthFlowType) –

    The authentication flow that you want to initiate. Each AuthFlow has linked AuthParameters that you must submit. The following are some example flows.

    USER_AUTH

    The entry point for choice-based authentication with passwords, one-time passwords, and WebAuthn authenticators. Request a preferred authentication type or review available authentication types. From the offered authentication types, select one in a challenge response and then authenticate with that method in an additional challenge response. To activate this setting, your user pool must be in the Essentials tier or higher.

    USER_SRP_AUTH

    Username-password authentication with the Secure Remote Password (SRP) protocol. For more information, see Use SRP password verification in custom authentication flow.

    REFRESH_TOKEN_AUTH and REFRESH_TOKEN

    Receive new ID and access tokens when you pass a REFRESH_TOKEN parameter with a valid refresh token as the value. For more information, see Using the refresh token.

    CUSTOM_AUTH

    Custom authentication with Lambda triggers. For more information, see Custom authentication challenge Lambda triggers.

    USER_PASSWORD_AUTH

    Client-side username-password authentication with the password sent directly in the request. For more information about client-side and server-side authentication, see SDK authorization models.

    ADMIN_USER_PASSWORD_AUTH is a flow type of AdminInitiateAuth and isn't valid for InitiateAuth. ADMIN_NO_SRP_AUTH is a legacy server-side username-password flow and isn't valid for InitiateAuth.

  • auth_parameters (Optional[AuthParametersType], default: None ) –

    The authentication parameters. These are inputs corresponding to the AuthFlow that you're invoking.

    The following are some authentication flows and their parameters. Add a SECRET_HASH parameter if your app client has a client secret. Add DEVICE_KEY if you want to bypass multi-factor authentication with a remembered device.

    USER_AUTH
    • USERNAME (required)

    • PREFERRED_CHALLENGE. If you don't provide a value for PREFERRED_CHALLENGE, Amazon Cognito responds with the AvailableChallenges parameter that specifies the available sign-in methods.

    • TARGET_ACR_VALUES. An optional, space-separated list of the authentication context class reference (ACR) level URIs that you want the user to reach. List the levels in priority order, from highest to lowest. Amazon Cognito attempts the highest-priority level that the user can satisfy, and falls back through the list. Amazon Cognito ignores any value that it doesn't recognize. If none of the requested values are valid, Amazon Cognito returns an error.

      Requesting step-up authentication with this parameter requires the Essentials or Plus feature plan. On a lower feature plan, InitiateAuth returns a FeatureUnavailableInTierException. USERNAME is required. When you provide an ACCESS_TOKEN, you must also provide TARGET_ACR_VALUES. Amazon Cognito returns an error if you provide an ACCESS_TOKEN without TARGET_ACR_VALUES. The USERNAME that you provide must match the user that the ACCESS_TOKEN was issued for.

      For more information about step-up authentication and how Amazon Cognito handles multi-factor authentication requirements, see Step-up authentication with ACR and AMR in the Amazon Cognito Developer Guide.

    • MAX_AGE. An optional integer that sets the maximum number of seconds allowed since the user last authenticated. If the user's most recent authentication is older than this value, Amazon Cognito discards the authentication-methods credit from any access token that you provide and processes the request as a fresh authentication toward the target level. The access token itself remains valid.

    USER_SRP_AUTH
    • USERNAME (required)

    • SRP_A (required)

    USER_PASSWORD_AUTH
    • USERNAME (required)

    • PASSWORD (required)

    REFRESH_TOKEN_AUTH/REFRESH_TOKEN
    • REFRESH_TOKEN(required)

    CUSTOM_AUTH
    • USERNAME (required)

    • ChallengeName: SRP_A (when doing SRP authentication before custom challenges)

    • SRP_A: (An SRP_A value) (when doing SRP authentication before custom challenges)

    For more information about SECRET_HASH, see Computing secret hash values. For information about DEVICE_KEY, see Working with user devices in your user pool.

  • 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.

    The ClientMetadata value is passed as input to the functions for only the following triggers:

    • Pre signup

    • Pre authentication

    • User migration

    This request also invokes the functions for the following triggers, but doesn't pass ClientMetadata:

    • Post authentication

    • Custom message

    • Pre token generation

    • Create auth challenge

    • Define auth challenge

    • Custom email sender

    • Custom SMS sender

    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.

  • client_id (ClientIdType) –

    The ID of the app client that your user wants to sign in to.

  • 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.

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

    The optional session ID from a ConfirmSignUp API request. You can sign in a user directly from the sign-up process with the USER_AUTH authentication flow. When you pass the session ID to InitiateAuth, Amazon Cognito assumes the SMS or email message one-time verification password from ConfirmSignUp as the primary authentication factor. You're not required to submit this code a second time. This option is only valid for users who have confirmed their sign-up and are signing in for the first time within the authentication flow session duration of the session ID.

Raises:

  • FeatureUnavailableInTierException –

    This exception is thrown when a feature that you attempted to use or configure isn't included in your user pool's current feature plan. This can occur when:

    • You configure a feature that your feature plan doesn't support.

    • You make a request that uses a feature that requires a higher feature plan.

    To resolve this issue, upgrade your user pool to a feature plan that includes the feature.

  • 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.

  • InvalidEmailRoleAccessPolicyException –

    This exception is thrown when Amazon Cognito isn't allowed to use your email identity. HTTP status code: 400.

  • 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.

  • InvalidSmsRoleAccessPolicyException –

    This exception is returned when the role provided for SMS configuration doesn't have permission to publish using Amazon SNS.

  • InvalidSmsRoleTrustRelationshipException –

    This exception is thrown when the trust relationship is not valid for the role provided for SMS configuration. This can happen if you don't trust cognito-idp.amazonaws.com or the external ID provided in the role does not match what is provided in the SMS configuration for the user pool.

  • InvalidUserPoolConfigurationException –

    This exception is thrown when the user pool configuration is not valid.

  • 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.

  • PasswordResetRequiredException –

    This exception is thrown when a password reset is required.

  • ResourceNotFoundException –

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

  • 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.

  • UnsupportedOperationException –

    Exception that is thrown when you attempt to perform an operation that isn't enabled for the user pool client.

  • UserLambdaValidationException –

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

  • UserNotConfirmedException –

    This exception is thrown when a user isn't confirmed successfully.

  • UserNotFoundException –

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

  • UnknownServiceError –

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

Examples:

Example username and password sign-in for a user who has TOTP MFA The following example signs in the user mytestuser with analytics data, client metadata, and user context data for advanced security.

>>> client.initiate_auth(auth_flow='USER_PASSWORD_AUTH', client_id='1example23456789', auth_parameters={'USERNAME': 'mytestuser', 'PASSWORD': 'This-is-my-test-99!', 'SECRET_HASH': 'oT5ZkS8ctnrhYeeGsGTvOzPhoc/Jd1cO5fueBWFVmp8='}, analytics_metadata={'AnalyticsEndpointId': 'd70b2ba36a8c4dc5a04a0451a31a1e12'}, user_context_data={'EncodedData': 'AmazonCognitoAdvancedSecurityData_object', 'IpAddress': '192.0.2.1'}, client_metadata={'MyTestKey': 'MyTestValue'})
Source code in docs_src/capo_cognito_identity_provider/_services/cognito_identity_provider.py
def initiate_auth(
    self,
    auth_flow: "capo_cognito_identity_provider.types.auth_flow_type.AuthFlowType",
    client_id: "capo_cognito_identity_provider.types.client_id_type.ClientIdType",
    *,
    config_overrides: Optional[CognitoIdentityProviderClientConfig] = None,
    auth_parameters: Optional[
        "capo_cognito_identity_provider.types.auth_parameters_type.AuthParametersType"
    ] = None,
    client_metadata: Optional[
        "capo_cognito_identity_provider.types.client_metadata_type.ClientMetadataType"
    ] = 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,
    session: Optional[
        "capo_cognito_identity_provider.types.session_type.SessionType"
    ] = None,
) -> "capo_cognito_identity_provider.types.initiate_auth_response.InitiateAuthResponse":
    """<p>Declares an authentication flow and initiates sign-in for a user in the Amazon Cognito user directory. Amazon Cognito might respond with an additional challenge or an <code>AuthenticationResult</code> that contains the outcome of a successful authentication. You can't sign in a user with a federated IdP with <code>InitiateAuth</code>. For more information, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/authentication.html">Authentication</a>.</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> <note> <p>This action might generate an SMS text message. Starting June 1, 2021, US telecom carriers require you to register an origination phone number before you can send SMS messages to US phone numbers. If you use SMS text messages in Amazon Cognito, you must register a phone number with <a href="https://console.aws.amazon.com/pinpoint/home/">Amazon Pinpoint</a>. Amazon Cognito uses the registered number automatically. Otherwise, Amazon Cognito users who must receive SMS messages might not be able to sign up, activate their accounts, or sign in.</p> <p>If you have never used SMS text messages with Amazon Cognito or any other Amazon Web Services service, Amazon Simple Notification Service might place your account in the SMS sandbox. In <i> <a href="https://docs.aws.amazon.com/sns/latest/dg/sns-sms-sandbox.html">sandbox mode</a> </i>, you can send messages only to verified phone numbers. After you test your app while in the sandbox environment, you can move out of the sandbox and into production. For more information, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-sms-settings.html"> SMS message settings for Amazon Cognito user pools</a> in the <i>Amazon Cognito Developer Guide</i>.</p> </note>

    Args:
        auth_flow: <p>The authentication flow that you want to initiate. Each <code>AuthFlow</code> has linked <code>AuthParameters</code> that you must submit. The following are some example flows.</p> <dl> <dt>USER_AUTH</dt> <dd> <p>The entry point for <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/authentication-flows-selection-sdk.html#authentication-flows-selection-choice">choice-based authentication</a> with passwords, one-time passwords, and WebAuthn authenticators. Request a preferred authentication type or review available authentication types. From the offered authentication types, select one in a challenge response and then authenticate with that method in an additional challenge response. To activate this setting, your user pool must be in the <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/feature-plans-features-essentials.html"> Essentials tier</a> or higher.</p> </dd> <dt>USER_SRP_AUTH</dt> <dd> <p>Username-password authentication with the Secure Remote Password (SRP) protocol. For more information, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html#Using-SRP-password-verification-in-custom-authentication-flow">Use SRP password verification in custom authentication flow</a>.</p> </dd> <dt>REFRESH_TOKEN_AUTH and REFRESH_TOKEN</dt> <dd> <p>Receive new ID and access tokens when you pass a <code>REFRESH_TOKEN</code> parameter with a valid refresh token as the value. For more information, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-the-refresh-token.html">Using the refresh token</a>.</p> </dd> <dt>CUSTOM_AUTH</dt> <dd> <p>Custom authentication with Lambda triggers. For more information, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-challenge.html">Custom authentication challenge Lambda triggers</a>.</p> </dd> <dt>USER_PASSWORD_AUTH</dt> <dd> <p>Client-side username-password authentication with the password sent directly in the request. For more information about client-side and server-side authentication, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/authentication-flows-public-server-side.html">SDK authorization models</a>.</p> </dd> </dl> <p> <code>ADMIN_USER_PASSWORD_AUTH</code> is a flow type of <code>AdminInitiateAuth</code> and isn't valid for InitiateAuth. <code>ADMIN_NO_SRP_AUTH</code> is a legacy server-side username-password flow and isn't valid for InitiateAuth.</p>
        auth_parameters: <p>The authentication parameters. These are inputs corresponding to the <code>AuthFlow</code> that you're invoking.</p> <p>The following are some authentication flows and their parameters. Add a <code>SECRET_HASH</code> parameter if your app client has a client secret. Add <code>DEVICE_KEY</code> if you want to bypass multi-factor authentication with a remembered device. </p> <dl> <dt>USER_AUTH</dt> <dd> <ul> <li> <p> <code>USERNAME</code> (required)</p> </li> <li> <p> <code>PREFERRED_CHALLENGE</code>. If you don't provide a value for <code>PREFERRED_CHALLENGE</code>, Amazon Cognito responds with the <code>AvailableChallenges</code> parameter that specifies the available sign-in methods.</p> </li> <li> <p> <code>TARGET_ACR_VALUES</code>. An optional, space-separated list of the authentication context class reference (ACR) level URIs that you want the user to reach. List the levels in priority order, from highest to lowest. Amazon Cognito attempts the highest-priority level that the user can satisfy, and falls back through the list. Amazon Cognito ignores any value that it doesn't recognize. If none of the requested values are valid, Amazon Cognito returns an error.</p> <p>Requesting step-up authentication with this parameter requires the Essentials or Plus feature plan. On a lower feature plan, InitiateAuth returns a FeatureUnavailableInTierException. <code>USERNAME</code> is required. When you provide an <code>ACCESS_TOKEN</code>, you must also provide <code>TARGET_ACR_VALUES</code>. Amazon Cognito returns an error if you provide an <code>ACCESS_TOKEN</code> without <code>TARGET_ACR_VALUES</code>. The <code>USERNAME</code> that you provide must match the user that the <code>ACCESS_TOKEN</code> was issued for.</p> <p>For more information about step-up authentication and how Amazon Cognito handles multi-factor authentication requirements, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-step-up-authentication.html">Step-up authentication with ACR and AMR</a> in the <i>Amazon Cognito Developer Guide</i>.</p> </li> <li> <p> <code>MAX_AGE</code>. An optional integer that sets the maximum number of seconds allowed since the user last authenticated. If the user's most recent authentication is older than this value, Amazon Cognito discards the authentication-methods credit from any access token that you provide and processes the request as a fresh authentication toward the target level. The access token itself remains valid.</p> </li> </ul> </dd> <dt>USER_SRP_AUTH</dt> <dd> <ul> <li> <p> <code>USERNAME</code> (required)</p> </li> <li> <p> <code>SRP_A</code> (required)</p> </li> </ul> </dd> <dt>USER_PASSWORD_AUTH</dt> <dd> <ul> <li> <p> <code>USERNAME</code> (required)</p> </li> <li> <p> <code>PASSWORD</code> (required)</p> </li> </ul> </dd> <dt>REFRESH_TOKEN_AUTH/REFRESH_TOKEN</dt> <dd> <ul> <li> <p> <code>REFRESH_TOKEN</code>(required)</p> </li> </ul> </dd> <dt>CUSTOM_AUTH</dt> <dd> <ul> <li> <p> <code>USERNAME</code> (required)</p> </li> <li> <p> <code>ChallengeName: SRP_A</code> (when doing SRP authentication before custom challenges)</p> </li> <li> <p> <code>SRP_A: (An SRP_A value)</code> (when doing SRP authentication before custom challenges)</p> </li> </ul> </dd> </dl> <p>For more information about <code>SECRET_HASH</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>. For information about <code>DEVICE_KEY</code>, see <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-device-tracking.html">Working with user devices in your user pool</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> <p>The <code>ClientMetadata</code> value is passed as input to the functions for only the following triggers:</p> <ul> <li> <p>Pre signup</p> </li> <li> <p>Pre authentication</p> </li> <li> <p>User migration</p> </li> </ul> <p>This request also invokes the functions for the following triggers, but doesn't pass <code>ClientMetadata</code>:</p> <ul> <li> <p>Post authentication</p> </li> <li> <p>Custom message</p> </li> <li> <p>Pre token generation</p> </li> <li> <p>Create auth challenge</p> </li> <li> <p>Define auth challenge</p> </li> <li> <p>Custom email sender</p> </li> <li> <p>Custom SMS sender</p> </li> </ul> <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>
        client_id: <p>The ID of the app client that your user wants to sign in to.</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>
        session: <p>The optional session ID from a <code>ConfirmSignUp</code> API request. You can sign in a user directly from the sign-up process with the <code>USER_AUTH</code> authentication flow. When you pass the session ID to <code>InitiateAuth</code>, Amazon Cognito assumes the SMS or email message one-time verification password from <code>ConfirmSignUp</code> as the primary authentication factor. You're not required to submit this code a second time. This option is only valid for users who have confirmed their sign-up and are signing in for the first time within the authentication flow session duration of the session ID.</p>

    Raises:
        capo_cognito_identity_provider.errors.feature_unavailable_in_tier_exception.FeatureUnavailableInTierException: <p>This exception is thrown when a feature that you attempted to use or configure isn't included in your user pool's current feature plan. This can occur when:</p> <ul> <li> <p>You configure a feature that your feature plan doesn't support.</p> </li> <li> <p>You make a request that uses a feature that requires a higher feature plan.</p> </li> </ul> <p>To resolve this issue, upgrade your user pool to a feature plan that includes the feature.</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_email_role_access_policy_exception.InvalidEmailRoleAccessPolicyException: <p>This exception is thrown when Amazon Cognito isn't allowed to use your email identity. HTTP status code: 400.</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.invalid_sms_role_access_policy_exception.InvalidSmsRoleAccessPolicyException: <p>This exception is returned when the role provided for SMS configuration doesn't have permission to publish using Amazon SNS.</p>
        capo_cognito_identity_provider.errors.invalid_sms_role_trust_relationship_exception.InvalidSmsRoleTrustRelationshipException: <p>This exception is thrown when the trust relationship is not valid for the role provided for SMS configuration. This can happen if you don't trust <code>cognito-idp.amazonaws.com</code> or the external ID provided in the role does not match what is provided in the SMS configuration for the user pool.</p>
        capo_cognito_identity_provider.errors.invalid_user_pool_configuration_exception.InvalidUserPoolConfigurationException: <p>This exception is thrown when the user pool configuration is not valid.</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.password_reset_required_exception.PasswordResetRequiredException: <p>This exception is thrown when a password reset is required.</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_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.unsupported_operation_exception.UnsupportedOperationException: <p>Exception that is thrown when you attempt to perform an operation that isn't enabled for the user pool client.</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_confirmed_exception.UserNotConfirmedException: <p>This exception is thrown when a user isn't confirmed successfully.</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.

    Examples:
        Example username and password sign-in for a user who has TOTP MFA
        The following example signs in the user mytestuser with analytics data, client metadata, and user context data for advanced security.

        >>> client.initiate_auth(auth_flow='USER_PASSWORD_AUTH', client_id='1example23456789', auth_parameters={'USERNAME': 'mytestuser', 'PASSWORD': 'This-is-my-test-99!', 'SECRET_HASH': 'oT5ZkS8ctnrhYeeGsGTvOzPhoc/Jd1cO5fueBWFVmp8='}, analytics_metadata={'AnalyticsEndpointId': 'd70b2ba36a8c4dc5a04a0451a31a1e12'}, user_context_data={'EncodedData': 'AmazonCognitoAdvancedSecurityData_object', 'IpAddress': '192.0.2.1'}, client_metadata={'MyTestKey': 'MyTestValue'})
    """

    def _handler(
        req: "OperationRequest[capo_cognito_identity_provider.types.initiate_auth_request.InitiateAuthRequest]",
    ) -> OperationResponse[
        "capo_cognito_identity_provider.types.initiate_auth_response.InitiateAuthResponse"
    ]:
        import capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.initiate_auth

        output, http_response = (
            capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.initiate_auth.initiate_auth(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

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

        return capo_cognito_identity_provider.types.initiate_auth_request.redact_sensitive(
            input_
        )

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

        return capo_cognito_identity_provider.types.initiate_auth_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "InitiateAuth", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_cognito_identity_provider.types.initiate_auth_request.InitiateAuthRequest = {
        "auth_flow": auth_flow,
        "client_id": client_id,
    }
    if auth_parameters is not None:
        input_["auth_parameters"] = auth_parameters
    if client_metadata is not None:
        input_["client_metadata"] = client_metadata
    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 session is not None:
        input_["session"] = session

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output