def steam_oAuthLogin(steamguard, token):
    steamguard = steamguard.split("||")
    steamid = sid.SteamID(steamguard[0])

    response = s.post(
        'https://api.steampowered.com/IMobileAuthService/GetWGToken/v1/',
        data={
            'access_token': token
        }).json()['response']

    # No token in response
    if not 'token' in response or not 'token_secure' in response:
        return False

    # Build cookie list
    cookies = {
        'steamLogin':
        str("{id}||{token}".format(id=steamid, token=response['token'])),
        'steamLoginSecure':
        str("{id}||{token}".format(id=steamid,
                                   token=response['token_secure'])),
        'steamMachineAuth' + str(steamid):
        steamguard[1],
        'sessionid':
        sweb.generate_session_id()
    }

    # Create cookie jar
    jar = requests.cookies.RequestsCookieJar()
    for cookie in cookies:
        jar.set(cookie, cookies[cookie], domain='steamcommunity.com', path='/')

    return jar
Пример #2
0
    def login(self, captcha='', email_code='', twofactor_code='', language='english'):
        """Attempts web login and returns on a session with cookies set

        :param captcha: text reponse for captcha challenge
        :type captcha: :class:`str`
        :param email_code: email code for steam guard
        :type email_code: :class:`str`
        :param twofactor_code: 2FA code for steam guard
        :type twofactor_code: :class:`str`
        :param language: select language for steam web pages (sets language cookie)
        :type language: :class:`str`
        :return: a session on success and :class:`None` otherwise
        :rtype: :class:`requests.Session`, :class:`None`
        :raises HTTPError: any problem with http request, timeouts, 5xx, 4xx etc
        :raises CaptchaRequired: when captcha is needed
        :raises EmailCodeRequired: when email is needed
        :raises TwoFactorCodeRequired: when 2FA is needed
        :raises LoginIncorrect: wrong username or password
        """
        if self.complete:
            return self.session

        self._load_key()
        resp = self._send_login(captcha=captcha, email_code=email_code, twofactor_code=twofactor_code)

        self.captcha_gid = -1

        if resp['success'] and resp['login_complete']:
            self.complete = True
            self.password = None

            for cookie in list(self.session.cookies):
                for domain in ['store.steampowered.com', 'help.steampowered.com', 'steamcommunity.com']:
                    self.session.cookies.set(cookie.name, cookie.value, domain=domain, secure=cookie.secure)

            self.session_id = generate_session_id()

            for domain in ['store.steampowered.com', 'help.steampowered.com', 'steamcommunity.com']:
                self.session.cookies.set('Steam_Language', language, domain=domain)
                self.session.cookies.set('birthtime', '-3333', domain=domain)
                self.session.cookies.set('sessionid', self.session_id, domain=domain)

            self._finalize_login(resp)

            return self.session
        else:
            if resp.get('captcha_needed', False):
                self.captcha_gid = resp['captcha_gid']

                raise CaptchaRequired(resp['message'])
            elif resp.get('emailauth_needed', False):
                self.steam_id = SteamID(resp['emailsteamid'])
                raise EmailCodeRequired(resp['message'])
            elif resp.get('requires_twofactor', False):
                raise TwoFactorCodeRequired(resp['message'])
            else:
                raise LoginIncorrect(resp['message'])

        return None
Пример #3
0
    def get_web_session(self, language='english'):
        """Get a :class:`requests.Session` that is ready for use

        See :meth:`get_web_session_cookies`

        .. note::
            Auth cookies will only be send to ``(help|store).steampowered.com`` and ``steamcommunity.com`` domains

        .. note::
            The session is valid only while :class:`.SteamClient` instance is logged on.

        :param language: localization language for steam pages
        :type language: :class:`str`
        :return: authenticated Session ready for use
        :rtype: :class:`requests.Session`, :class:`None`
        """
        if self._web_session:
            return self._web_session

        cookies = self.get_web_session_cookies()
        if cookies is None:
            return None

        self._web_session = session = make_requests_session()
        session_id = generate_session_id()

        for domain in [
                'store.steampowered.com', 'help.steampowered.com',
                'steamcommunity.com'
        ]:
            for name, val in cookies.items():
                secure = (name == 'steamLoginSecure')
                session.cookies.set(name, val, domain=domain, secure=secure)

            session.cookies.set('Steam_Language', language, domain=domain)
            session.cookies.set('birthtime', '-3333', domain=domain)
            session.cookies.set('sessionid', session_id, domain=domain)

        return session
Пример #4
0
    def get_web_session(self, language='english'):
        """Get a :class:`requests.Session` that is ready for use

        See :meth:`get_web_session_cookies`

        .. note::
            Auth cookies will only be send to ``(help|store).steampowered.com`` and ``steamcommunity.com`` domains

        .. note::
            The session is valid only while :class:`.SteamClient` instance is logged on.

        :param language: localization language for steam pages
        :type language: :class:`str`
        :return: authenticated Session ready for use
        :rtype: :class:`requests.Session`, :class:`None`
        """
        if self._web_session:
            return self._web_session

        cookies = self.get_web_session_cookies()
        if cookies is None:
            return None

        self._web_session = session = make_requests_session()
        session_id = generate_session_id()

        for domain in ['store.steampowered.com', 'help.steampowered.com', 'steamcommunity.com']:
            for name, val in cookies.items():
                secure = (name == 'steamLoginSecure')
                session.cookies.set(name, val, domain=domain, secure=secure)

            session.cookies.set('Steam_Language', language, domain=domain)
            session.cookies.set('birthtime', '-3333', domain=domain)
            session.cookies.set('sessionid', session_id, domain=domain)

        return session
Пример #5
0
    def login(self,
              captcha='',
              email_code='',
              twofactor_code='',
              language='english'):
        """Attempts web login and returns on a session with cookies set

        :param captcha: text reponse for captcha challenge
        :type captcha: :class:`str`
        :param email_code: email code for steam guard
        :type email_code: :class:`str`
        :param twofactor_code: 2FA code for steam guard
        :type twofactor_code: :class:`str`
        :param language: select language for steam web pages (sets language cookie)
        :type language: :class:`str`
        :return: a session on success and :class:`None` otherwise
        :rtype: :class:`requests.Session`, :class:`None`
        :raises HTTPError: any problem with http request, timeouts, 5xx, 4xx etc
        :raises CaptchaRequired: when captcha is needed
        :raises EmailCodeRequired: when email is needed
        :raises TwoFactorCodeRequired: when 2FA is needed
        :raises LoginIncorrect: wrong username or password
        """
        if self.complete:
            return self.session

        self._load_key()
        resp = self._send_login(captcha=captcha,
                                email_code=email_code,
                                twofactor_code=twofactor_code)

        self.captcha_gid = -1

        if resp['success'] and resp['login_complete']:
            self.complete = True
            self.password = None

            for cookie in list(self.session.cookies):
                for domain in [
                        'store.steampowered.com', 'help.steampowered.com',
                        'steamcommunity.com'
                ]:
                    self.session.cookies.set(cookie.name,
                                             cookie.value,
                                             domain=domain,
                                             secure=cookie.secure)

            self.session_id = generate_session_id()

            for domain in [
                    'store.steampowered.com', 'help.steampowered.com',
                    'steamcommunity.com'
            ]:
                self.session.cookies.set('Steam_Language',
                                         language,
                                         domain=domain)
                self.session.cookies.set('birthtime', '-3333', domain=domain)
                self.session.cookies.set('sessionid',
                                         self.session_id,
                                         domain=domain)

            self._finalize_login(resp)

            return self.session
        else:
            if resp.get('captcha_needed', False):
                self.captcha_gid = resp['captcha_gid']

                raise CaptchaRequired(resp['message'])
            elif resp.get('emailauth_needed', False):
                self.steam_id = SteamID(resp['emailsteamid'])
                raise EmailCodeRequired(resp['message'])
            elif resp.get('requires_twofactor', False):
                raise TwoFactorCodeRequired(resp['message'])
            else:
                raise LoginIncorrect(resp['message'])

        return None
Пример #6
0
 def _steamAuth(self,
                account=None,
                password=None,
                steamID=None,
                auth_token=None,
                steamguard_token=None):
     """
 Aliased internal function for steam auth. If used with plain username and password
 returns dict with a status request for 2FA when required. Use <>.postSteam2FA() after
 Possible statuses:
 0 - No 2FA required - Plain login, you can now use session
 1 - Captcha required - Post the captcha code
 2 - Email code required - Post the code received on the email
 3 - Steamguard 2FA required - Post the 2FA code from steamguard
 """
     if account and password:
         if not 'sessionid' in self.session.cookies.get_dict():
             self.steamUser = wa.MobileWebAuth(account, password)
             try:
                 self.steamUser.login()
                 self.session.cookies.update(self.steamUser.session.cookies)
                 self._steamSiteLogin()
                 return {
                     "status": 0,
                     "message": "No 2FA required. Check user session"
                 }
             except wa.CaptchaRequired:
                 self.twofaType = "captcha"
                 return {
                     "status": 1,
                     "message": "Captcha Required",
                     "url": self.steamUser.captcha_url
                 }  # User must .postSteam2FA(code)
             except wa.EmailCodeRequired:
                 self.twofaType = "email"
                 return {
                     "status": 2,
                     "message": "Email code Required"
                 }  # User must .postSteam2FA(code)
             except wa.TwoFactorCodeRequired:
                 self.twofaType = "steamguard"
                 return {
                     "status": 3,
                     "message": "Steamguard 2FA Required"
                 }  # User must .postSteam2FA(code)
     elif steamID and auth_token and steamguard_token:
         steamid = sid.SteamID(steamID)
         try:
             response = self.session.post(
                 'https://api.steampowered.com/IMobileAuthService/GetWGToken/v1/',
                 data={
                     'access_token': auth_token
                 }).json()['response']
         except:
             return self._steamSiteLogin()
         if not 'token' in response or not 'token_secure' in response:
             return False
         cookies = {
             'steamLogin': f"{steamid}||{response['token']}",
             'steamLoginSecure': f"{steamid}||{response['token_secure']}",
             f'steamMachineAuth{steamid}': steamguard_token,
             'sessionid': sweb.generate_session_id()
         }
         jar = requests.cookies.RequestsCookieJar()
         for cookie in cookies:
             jar.set(cookie,
                     cookies[cookie],
                     domain='steamcommunity.com',
                     path='/')
         self.session.cookies.update(jar)
         return self._steamSiteLogin()
     else:
         raise MissingSteamLoginData