Browse Source

added get_web_session feature

Allows for interacting with steamcommunity and store
pull/18/merge
Rossen Georgiev 9 years ago
parent
commit
15275315bb
  1. 8
      docs/api/steam.client.features.rst
  2. 1
      steam/client/__init__.py
  3. 3
      steam/client/features/__init__.py
  4. 68
      steam/client/features/web.py

8
docs/api/steam.client.features.rst

@ -11,6 +11,14 @@ User
:undoc-members:
:show-inheritance:
Web
---
.. automodule:: steam.client.features.web
:members:
:undoc-members:
:show-inheritance:
Misc
----

1
steam/client/__init__.py

@ -23,6 +23,7 @@ class SteamClient(EventEmitter, FeatureBase):
current_jobid = 0
credential_location = None #: location for sentry
username = None #: username when logged on
_logger = logger
def __init__(self):
self.cm = CMClient()

3
steam/client/features/__init__.py

@ -3,8 +3,9 @@ All high level features of :class:`steam.client.SteamClient` are here in seperat
"""
from steam.client.features.misc import Misc
from steam.client.features.user import User
from steam.client.features.web import Web
class FeatureBase(Misc, User):
class FeatureBase(Misc, User, Web):
"""
This object is used as base to implement all high level functionality.
The features are seperated into submodules.

68
steam/client/features/web.py

@ -0,0 +1,68 @@
"""
Web related features
"""
from Crypto.Hash import SHA
from Crypto.Random import new as randombytes
from steam import WebAPI
from steam.core.crypto import generate_session_key, symmetric_encrypt
from steam.util.web import make_requests_session
class Web(object):
def __init__(self):
super(Web, self).__init__()
def get_web_session_cookies(self):
"""
Get web authentication cookies via WebAPI's ``AuthenticateUser``
.. note::
only valid during the current steam session
:return: dict with authentication cookies
:rtype: :class:`dict`, :class:`None`
"""
if not self.logged_on:
return None
skey, ekey = generate_session_key()
data = {
'steamid': self.steam_id,
'sessionkey': ekey,
'encrypted_loginkey': symmetric_encrypt(self.cm.webapi_authenticate_user_nonce, skey),
}
try:
api = WebAPI(None)
resp = api.ISteamUserAuth.AuthenticateUser(**data)
except Exception as exp:
self._logger.debug("get_web_session_cookies error: %s" % str(exp))
return None
return {
'sessionid': SHA.new(randombytes().read(32)).hexdigest(),
'steamLogin': resp['authenticateuser']['token'],
'steamLoginSecure': resp['authenticateuser']['tokensecure'],
}
def get_web_session(self):
"""
See :meth:`get_web_session_cookies`
:return: authenticated session ready for use
:rtype: :class:`requests.Session`, :class:`None`
"""
cookies = self.get_web_session_cookies()
if cookies is None:
return None
session = make_requests_session()
for name, val in cookies.items():
session.cookies.set(name, val)
return session
Loading…
Cancel
Save