Ejemplo n.º 1
0
    def finalize(self, activation_code):
        """Finalize authenticator with received SMS code

        :param activation_code: SMS code
        :type activation_code: str
        :raises: :class:`SteamAuthenticatorError`
        """
        resp = self._send_request(
            'FinalizeAddAuthenticator', {
                'steamid': self.backend.steam_id,
                'authenticator_time': int(time()),
                'authenticator_code': self.get_code(),
                'activation_code': activation_code,
            })

        if resp['status'] != EResult.TwoFactorActivationCodeMismatch and resp.get(
                'want_more', False) and self._finalize_attempts:
            self.steam_time_offset += 30
            self._finalize_attempts -= 1
            self.finalize(activation_code)
            return
        elif not resp['success']:
            self._finalize_attempts = 5
            raise SteamAuthenticatorError(
                "Failed to finalize authenticator. Error: %s" %
                repr(EResult(resp['status'])))

        self.steam_time_offset = int(resp['server_time']) - time()
Ejemplo n.º 2
0
    def add(self):
        """Add authenticator to an account.
        The account's phone number will receive a SMS code required for :meth:`finalize`.

        :raises: :class:`SteamAuthenticatorError`
        """
        if not self.has_phone_number():
            raise SteamAuthenticatorError(
                "Account doesn't have a verified phone number")

        resp = self._send_request(
            'AddAuthenticator', {
                'steamid': self.backend.steam_id,
                'authenticator_time': int(time()),
                'authenticator_type': int(ETwoFactorTokenType.ValveMobileApp),
                'device_identifier': generate_device_id(self.backend.steam_id),
                'sms_phone_id': '1',
            })

        if resp['status'] != EResult.OK:
            raise SteamAuthenticatorError(
                "Failed to add authenticator. Error: %s" %
                repr(EResult(resp['status'])))

        self.secrets = resp
        self.steam_time_offset = int(resp['server_time']) - time()