def _send_request(self, action, params): medium = self.medium if isinstance(medium, MobileWebAuth): if not medium.complete: raise SteamAuthenticatorError("MobileWebAuth instance not logged in") params['access_token'] = medium.oauth_token params['http_timeout'] = 10 try: resp = webapi.post('ITwoFactorService', action, 1, params=params) except requests.exceptions.RequestException as exp: raise SteamAuthenticatorError("Error adding via WebAPI: %s" % str(exp)) resp = resp['response'] else: if not medium.logged_on: raise SteamAuthenticatorError("SteamClient instance not logged in") resp = medium.unified_messages.send_and_wait("TwoFactor.%s#1" % action, params, timeout=10) if resp is None: raise SteamAuthenticatorError("Failed to add authenticator. Request timeout") resp = proto_to_dict(resp) if action == 'AddAuthenticator': for key in ['shared_secret', 'identity_secret', 'secret_1']: resp[key] = b64encode(resp[key]) return resp
def get_web_session_cookies(self): """Get web authentication cookies via WebAPI's ``AuthenticateUser`` .. note:: A session is only valid during the current steam session. :return: dict with authentication cookies :rtype: :class:`dict`, :class:`None` """ if not self.logged_on: return None resp = self.send_job_and_wait(MsgProto(EMsg.ClientRequestWebAPIAuthenticateUserNonce), timeout=5) if resp is None: return None skey, ekey = generate_session_key() data = { 'steamid': self.steam_id, 'sessionkey': ekey, 'encrypted_loginkey': symmetric_encrypt(resp.webapi_authenticate_user_nonce.encode('ascii'), skey), } try: resp = webapi.post('ISteamUserAuth', 'AuthenticateUser', 1, params=data) except Exception as exp: self._logger.debug("get_web_session_cookies error: %s" % str(exp)) return None return { 'steamLogin': resp['authenticateuser']['token'], 'steamLoginSecure': resp['authenticateuser']['tokensecure'], }
def get_web_session_cookies(self): """Get web authentication cookies via WebAPI's ``AuthenticateUser`` .. note:: A session is 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.webapi_authenticate_user_nonce, skey), } try: resp = webapi.post('ISteamUserAuth', 'AuthenticateUser', 1, params=data) except Exception as exp: self._logger.debug("get_web_session_cookies error: %s" % str(exp)) return None return { 'sessionid': hexlify(sha1_hash(random_bytes(32))), 'steamLogin': resp['authenticateuser']['token'], 'steamLoginSecure': resp['authenticateuser']['tokensecure'], }
def test_post(self): resp = webapi.post('ISteamRemoteStorage', 'GetPublishedFileDetails', 1, session=self.api.session, params={ 'key': test_api_key, 'itemcount': 5, 'publishedfileids': [1,1,1,1,1], }) self.assertEqual(resp['response']['resultcount'], 5)
def get_time_offset(): """Get time offset from steam server time via WebAPI :return: time offset (``None`` when Steam WebAPI fails to respond) :rtype: :class:`int`, :class:`None` """ try: resp = webapi.post('ITwoFactorService', 'QueryTime', 1, params={'http_timeout': 10}) except: return None ts = int(time()) return int(resp.get('response', {}).get('server_time', ts)) - ts
def get_time_offset(): """Get time offset from steam server time via WebAPI :return: time offset :rtype: int """ try: resp = webapi.post('ITwoFactorService', 'QueryTime', 1, params={'http_timeout': 5}) except: return 0 ts = int(time()) return int(resp.get('response', {}).get('server_time', ts)) - ts
def _send_request(self, action, params): backend = self.backend if isinstance(backend, MobileWebAuth): if not backend.logged_on: raise SteamAuthenticatorError( "MobileWebAuth instance not logged in") params['access_token'] = backend.oauth_token params['http_timeout'] = 10 try: resp = webapi.post('ITwoFactorService', action, 1, params=params) except requests.exceptions.RequestException as exp: raise SteamAuthenticatorError("Error adding via WebAPI: %s" % str(exp)) resp = resp['response'] else: if not backend.logged_on: raise SteamAuthenticatorError( "SteamClient instance not logged in") resp = backend.send_um_and_wait("TwoFactor.%s#1" % action, params, timeout=10) if resp is None: raise SteamAuthenticatorError("Failed. Request timeout") if resp.header.eresult != EResult.OK: raise SteamAuthenticatorError( "Failed: %s (%s)" % str(resp.header.error_message, repr(resp.header.eresult))) resp = proto_to_dict(resp.body) if action == 'AddAuthenticator': for key in ['shared_secret', 'identity_secret', 'secret_1']: resp[key] = b64encode(resp[key]).decode('ascii') return resp