|
61 | 61 | import six
|
62 | 62 | import requests
|
63 | 63 |
|
64 |
| -from steam import webapi |
65 | 64 | from steam.steamid import SteamID
|
66 | 65 | from steam.util.web import make_requests_session, generate_session_id
|
67 | 66 | from steam.core.crypto import rsa_publickey, pkcs1v15_encrypt
|
68 | 67 |
|
69 | 68 | if six.PY2:
|
| 69 | + # noinspection PyUnresolvedReferences |
70 | 70 | intBase = long
|
| 71 | + # noinspection PyUnresolvedReferences |
71 | 72 | _cli_input = raw_input
|
72 | 73 | else:
|
73 | 74 | intBase = int
|
@@ -325,6 +326,57 @@ def _finalize_login(self, login_response):
|
325 | 326 | self.steam_id = SteamID(data['steamid'])
|
326 | 327 | self.oauth_token = data['oauth_token']
|
327 | 328 |
|
| 329 | + def oauth_login(self, oauth_token='', steam_id='', language='english'): |
| 330 | + if oauth_token: |
| 331 | + self.oauth_token = oauth_token |
| 332 | + else: |
| 333 | + if self.oauth_token: |
| 334 | + oauth_token = self.oauth_token |
| 335 | + else: |
| 336 | + raise LoginIncorrect('token is not specified') |
| 337 | + |
| 338 | + if steam_id: |
| 339 | + self.steam_id = SteamID(steam_id) |
| 340 | + else: |
| 341 | + if not self.steam_id: |
| 342 | + raise LoginIncorrect('steam_id is not specified') |
| 343 | + |
| 344 | + steam_id = self.steam_id.as_64 |
| 345 | + |
| 346 | + data = { |
| 347 | + 'access_token': oauth_token |
| 348 | + } |
| 349 | + |
| 350 | + try: |
| 351 | + resp = self.session.post('https://api.steampowered.com/IMobileAuthService/GetWGToken/v0001', data=data) |
| 352 | + except requests.exceptions.RequestException as e: |
| 353 | + raise HTTPError(str(e)) |
| 354 | + |
| 355 | + try: |
| 356 | + resp_data = resp.json()['response'] |
| 357 | + except json.decoder.JSONDecodeError as e: |
| 358 | + if 'Please verify your <pre>key=</pre> parameter.' in resp.text: |
| 359 | + raise LoginIncorrect('invalid token') |
| 360 | + else: |
| 361 | + raise WebAuthException('failed to decode response') |
| 362 | + |
| 363 | + self.session_id = generate_session_id() |
| 364 | + |
| 365 | + for domain in ['store.steampowered.com', 'help.steampowered.com', 'steamcommunity.com']: |
| 366 | + self.session.cookies.set('steamid', steam_id, domain=domain) |
| 367 | + self.session.cookies.set('birthtime', '-3333', domain=domain) |
| 368 | + self.session.cookies.set('sessionid', self.session_id, domain=domain) |
| 369 | + self.session.cookies.set('mobileClientVersion', '0 (2.1.3)', domain=domain) |
| 370 | + self.session.cookies.set('mobileClient', 'android', domain=domain) |
| 371 | + self.session.cookies.set('steamLogin', str(steam_id) + "%7C%7C" + resp_data['token'], domain=domain) |
| 372 | + self.session.cookies.set('steamLoginSecure', str(steam_id) + "%7C%7C" + resp_data['token_secure'], |
| 373 | + domain=domain, secure=True) |
| 374 | + self.session.cookies.set('Steam_Language', language, domain=domain) |
| 375 | + |
| 376 | + self.logged_on = True |
| 377 | + |
| 378 | + return self.session |
| 379 | + |
328 | 380 |
|
329 | 381 | class WebAuthException(Exception):
|
330 | 382 | pass
|
|
0 commit comments