Skip to content

verify_software_token

verify_software_token(
    user_code: SoftwareTokenMFAUserCodeType,
    *,
    config_overrides: Optional[CognitoIdentityProviderClientConfig] = None,
    access_token: Optional[TokenModelType] = None,
    session: Optional[SessionType] = None,
    friendly_device_name: Optional[StringType] = None,
) -> VerifySoftwareTokenResponse

Registers the current user's time-based one-time password (TOTP) authenticator with a code generated in their authenticator app from a private key that's supplied by your user pool. Marks the user's software token MFA status as "verified" if successful. The request takes an access token or a session string, but not both.

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:

  • access_token (Optional[TokenModelType], default: None ) –

    A valid access token that Amazon Cognito issued to the currently signed-in user. Must include a scope claim for aws.cognito.signin.user.admin.

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

    The session ID from an AssociateSoftwareToken request.

  • user_code (SoftwareTokenMFAUserCodeType) –

    A TOTP that the user generated in their configured authenticator app.

  • friendly_device_name (Optional[StringType], default: None ) –

    A friendly name for the device that's running the TOTP authenticator.

Raises:

  • CodeMismatchException –

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

  • EnableSoftwareTokenMFAException –

    This exception is thrown when there is a code mismatch and the service fails to configure the software token TOTP multi-factor authentication (MFA).

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

  • InvalidParameterException –

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

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

  • SoftwareTokenMFANotFoundException –

    This exception is thrown when the software token time-based one-time password (TOTP) multi-factor authentication (MFA) isn't activated for the user pool.

  • TooManyRequestsException –

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

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

Source code in docs_src/capo_cognito_identity_provider/_services/cognito_identity_provider.py
def verify_software_token(
    self,
    user_code: "capo_cognito_identity_provider.types.software_token_mfa_user_code_type.SoftwareTokenMFAUserCodeType",
    *,
    config_overrides: Optional[CognitoIdentityProviderClientConfig] = None,
    access_token: Optional[
        "capo_cognito_identity_provider.types.token_model_type.TokenModelType"
    ] = None,
    session: Optional[
        "capo_cognito_identity_provider.types.session_type.SessionType"
    ] = None,
    friendly_device_name: Optional[
        "capo_cognito_identity_provider.types.string_type.StringType"
    ] = None,
) -> "capo_cognito_identity_provider.types.verify_software_token_response.VerifySoftwareTokenResponse":
    """<p>Registers the current user's time-based one-time password (TOTP) authenticator with a code generated in their authenticator app from a private key that's supplied by your user pool. Marks the user's software token MFA status as "verified" if successful. The request takes an access token or a session string, but not both.</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:
        access_token: <p>A valid access token that Amazon Cognito issued to the currently signed-in user. Must include a scope claim for <code>aws.cognito.signin.user.admin</code>.</p>
        session: <p>The session ID from an <code>AssociateSoftwareToken</code> request.</p>
        user_code: <p>A TOTP that the user generated in their configured authenticator app.</p>
        friendly_device_name: <p>A friendly name for the device that's running the TOTP authenticator.</p>

    Raises:
        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.enable_software_token_mfa_exception.EnableSoftwareTokenMFAException: <p>This exception is thrown when there is a code mismatch and the service fails to configure the software token TOTP multi-factor authentication (MFA).</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_parameter_exception.InvalidParameterException: <p>This exception is thrown when the Amazon Cognito service encounters an invalid parameter.</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.software_token_mfa_not_found_exception.SoftwareTokenMFANotFoundException: <p>This exception is thrown when the software token time-based one-time password (TOTP) multi-factor authentication (MFA) isn't activated for the user pool.</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.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.
    """

    def _handler(
        req: "OperationRequest[capo_cognito_identity_provider.types.verify_software_token_request.VerifySoftwareTokenRequest]",
    ) -> OperationResponse[
        "capo_cognito_identity_provider.types.verify_software_token_response.VerifySoftwareTokenResponse"
    ]:
        import capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.verify_software_token

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

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

        return capo_cognito_identity_provider.types.verify_software_token_request.redact_sensitive(
            input_
        )

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

        return capo_cognito_identity_provider.types.verify_software_token_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "VerifySoftwareToken",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_cognito_identity_provider.types.verify_software_token_request.VerifySoftwareTokenRequest = {
        "user_code": user_code
    }
    if access_token is not None:
        input_["access_token"] = access_token
    if session is not None:
        input_["session"] = session
    if friendly_device_name is not None:
        input_["friendly_device_name"] = friendly_device_name

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