def verify_factor(self, user_id, device_id, otp_token=None, state_token=None):
self.clean_error()<EOL>try:<EOL><INDENT>url = self.get_url(Constants.VERIFY_FACTOR_URL, user_id, device_id)<EOL>data = {}<EOL>if otp_token:<EOL><INDENT>data['<STR_LIT>'] = otp_token<EOL><DEDENT>if state_token:<EOL><INDENT>data['<STR_LIT>'] = state_token<EOL><DEDENT>response = self.execute_call('<STR_LIT>', url, json=data)<EOL>if response.status_code == <NUM_LIT:200>:<EOL><INDENT>return self.handle_operation_response(response)<EOL><DEDENT>else:<EOL><INDENT>self.error = str(response.status_code)<EOL>self.error_description = self.extract_error_message_from_response(response)<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>self.error = <NUM_LIT><EOL>self.error_description = e.args[<NUM_LIT:0>]<EOL><DEDENT>return False<EOL>
Authenticates a one-time password (OTP) code provided by a multifactor authentication (MFA) device.

:param user_id: Set to the id of the user.
:type user_id: integer

:param device_id: Set to the device_id of the MFA device.
:type device_id: integer

:param otp_token: OTP code provided by the device or SMS message sent to user.
                  When a device like OneLogin Protect that supports Push has
                  been used you do not need to provide the otp_token.
:type otp_token: string

:param state_token: The state_token is returned after a successful request
                    to Enroll a Factor or Activate a Factor.
                    MUST be provided if the needs_trigger attribute from
                    the proceeding calls is set to true.
:type state_token: string

:return: true if action succeed
:rtype: bool

See https://developers.onelogin.com/api-docs/1/multi-factor-authentication/verify-factor Verify an Authentication Factor documentation