Browse Source

web session: send cookies only to steam domains

* cookies are now only send to steam domains
* set default language to english
* set birthtime cookies to avoid age check redirects
pull/34/head
Rossen Georgiev 9 years ago
parent
commit
f650a0fb0b
  1. 27
      steam/client/builtins/web.py

27
steam/client/builtins/web.py

@ -13,8 +13,7 @@ class Web(object):
super(Web, self).__init__(*args, **kwargs) super(Web, self).__init__(*args, **kwargs)
def get_web_session_cookies(self): def get_web_session_cookies(self):
""" """Get web authentication cookies via WebAPI's ``AuthenticateUser``
Get web authentication cookies via WebAPI's ``AuthenticateUser``
.. note:: .. note::
only valid during the current steam session only valid during the current steam session
@ -46,16 +45,17 @@ class Web(object):
'steamLoginSecure': resp['authenticateuser']['tokensecure'], 'steamLoginSecure': resp['authenticateuser']['tokensecure'],
} }
def get_web_session(self): def get_web_session(self, language='english'):
""" """Get a :class:`requests.Session` that is ready for use
See :meth:`get_web_session_cookies` See :meth:`get_web_session_cookies`
.. warning:: .. note::
Exercise caution when using the session. Auth cookies will only be send to ``.steampowered.com`` and ``.steamcommunity.com`` domains
Auth cookies will be send with every request,
regardless of the domain or https/http.
:return: authenticated session ready for use :param language: localization language for steam pages
:type language: :class:`str`
:return: authenticated Session ready for use
:rtype: :class:`requests.Session`, :class:`None` :rtype: :class:`requests.Session`, :class:`None`
""" """
cookies = self.get_web_session_cookies() cookies = self.get_web_session_cookies()
@ -64,7 +64,12 @@ class Web(object):
session = make_requests_session() session = make_requests_session()
for name, val in cookies.items(): for domain in ['.steampowered.com', '.steamcommunity.com']:
session.cookies.set(name, val) 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)
return session return session

Loading…
Cancel
Save