Exemplo n.º 1
0
    def login(self, username, password, authy_token=None, recaptcha_challenge=None, recaptcha_response=None,
              *args, **kwargs):
        """
        Login to the Humble Bundle API. The response sets the _simpleauth_sess cookie which is stored in the session
        automatically.

        :param str username: The user account to authenticate with
        :param str password: The password to authenticate with
        :param authy_token: (optional) The GoogleAuthenticator/Authy token (One time pass)
        :type authy_token: integer or str
        :param str recaptcha_challenge: (optional) The challenge signed by Humble Bundle's public key from reCAPTCHA
        :param str recaptcha_response: (optional) The plaintext solved CAPTCHA
        :param list args: (optional) Extra positional args to pass to the request
        :param dict kwargs: (optional) Extra keyword args to pass to the request. If a data dict is supplied a key
                            collision with any of the above params will resolved in favor of the supplied param
        :return: A Future object encapsulating the login request
        :rtype: Future
        :raises RequestException: if the connection failed
        :raises HumbleResponseException: if the response was invalid
        :raises HumbleCredentialException: if the username and password did not match
        :raises HumbleCaptchaException: if the captcha challenge failed
        :raises HumbleTwoFactorException: if the two-factor authentication challenge failed
        :raises HumbleAuthenticationException: if some other authentication error occurred

        """

        self.logger.info("Logging in")

        default_data = {
            'username': username,
            'password': password,
            'authy-token': authy_token,
            'recaptcha_challenge_field': recaptcha_challenge,
            'recaptcha_response_field': recaptcha_response}

        # We will need a valid csrf token

        # Pull down the LOGIN_URL in a GET request and pull the csrf token
        response = self._request('GET', LOGIN_URL, [], {})

        matches = re.search(r'<input([^>]*?)name\s*=\s*["\']_le_csrf_token["\']([^>]*?)>', response.text)
        if not matches is None:
            # Parse the value from the input attribute to provide the token
            value = "%s %s" % (matches.group(1), matches.group(2))
            matches = re.search(r'value\s*=\s*["\'](.*?)["\']', value)

        if not matches is None:
            default_data["_le_csrf_token"] = matches.group(1)

        kwargs.setdefault('data', {}).update({k: v for k, v in default_data.items() if v is not None})

        response = self._request('POST', LOGIN_URL, *args, **kwargs)
        return handlers.login_handler(self, response)
Exemplo n.º 2
0
    def login(self, username, password, authy_token=None,
              recaptcha_challenge=None, recaptcha_response=None,
              *args, **kwargs):
        """
        Login to the Humble Bundle API. The response sets the _simpleauth_sess
        cookie which is stored in the session automatically.

        :param str username: The user account to authenticate with
        :param str password: The password to authenticate with
        :param authy_token: (optional) The GoogleAuthenticator/Authy token
                            (One time pass)
        :type authy_token: integer or str
        :param str recaptcha_challenge: (optional) The challenge signed by
                                       Humble Bundle's public key from reCAPTCHA
        :param str recaptcha_response: (optional) The plaintext solved CAPTCHA
        :param list args: (optional) Extra positional args to pass
                          to the request
        :param dict kwargs: (optional) Extra keyword args to pass to the
                            request. If a data dict is supplied a key collision
                            with any of the above params will resolved in favor
                            of the supplied param
        :return: A Future object encapsulating the login request
        :rtype: Future
        :raises RequestException: if the connection failed
        :raises HumbleResponseException: if the response was invalid
        :raises HumbleCredentialException: if the username and password
                                           did not match
        :raises HumbleCaptchaException: if the captcha challenge failed
        :raises HumbleTwoFactorException: if the two-factor authentication
                                          challenge failed
        :raises HumbleAuthenticationException: if some other authentication
                                               error occurred

        """

        self.logger.info("Logging in")

        default_data = {
            'username': username,
            'password': password,
            'authy-token': authy_token,
            'recaptcha_challenge_field': recaptcha_challenge,
            'recaptcha_response_field': recaptcha_response
        }
        kwargs.setdefault('data', {}).update({
            k: v for k, v in default_data.items() if v is not None
        })

        response = self._request('POST', LOGIN_URL, *args, **kwargs)
        return handlers.login_handler(self, response)
Exemplo n.º 3
0
    def login(self,
              username,
              password,
              authy_token=None,
              recaptcha_challenge=None,
              recaptcha_response=None,
              *args,
              **kwargs):
        """
        Login to the Humble Bundle API. The response sets the _simpleauth_sess cookie which is stored in the session
        automatically.

        :param str username: The user account to authenticate with
        :param str password: The password to authenticate with
        :param authy_token: (optional) The GoogleAuthenticator/Authy token (One time pass)
        :type authy_token: integer or str
        :param str recaptcha_challenge: (optional) The challenge signed by Humble Bundle's public key from reCAPTCHA
        :param str recaptcha_response: (optional) The plaintext solved CAPTCHA
        :param list args: (optional) Extra positional args to pass to the request
        :param dict kwargs: (optional) Extra keyword args to pass to the request. If a data dict is supplied a key
                            collision with any of the above params will resolved in favor of the supplied param
        :return: A Future object encapsulating the login request
        :rtype: Future
        :raises RequestException: if the connection failed
        :raises HumbleResponseException: if the response was invalid
        :raises HumbleCredentialException: if the username and password did not match
        :raises HumbleCaptchaException: if the captcha challenge failed
        :raises HumbleTwoFactorException: if the two-factor authentication challenge failed
        :raises HumbleAuthenticationException: if some other authentication error occurred

        """

        self.logger.info("Logging in")

        default_data = {
            'username': username,
            'password': password,
            'authy-token': authy_token,
            'recaptcha_challenge_field': recaptcha_challenge,
            'recaptcha_response_field': recaptcha_response
        }
        kwargs.setdefault('data', {}).update(
            {k: v
             for k, v in default_data.items() if v is not None})

        response = self._request('POST', LOGIN_URL, *args, **kwargs)
        return handlers.login_handler(self, response)