steam icon indicating copy to clipboard operation
steam copied to clipboard

WebAuth class fixed. New api used. Email/guard code auth added.

Open artur1214 opened this issue 2 years ago • 12 comments

TODO: QR code auth add. Added function to unlogin on every device. Code refactoring done: added docstrings, typehints. NOTE: Current version now don't work with python <=3.5

artur1214 avatar Oct 28 '23 11:10 artur1214

This will solve https://github.com/ValvePython/steam/issues/451 https://github.com/ValvePython/steam/issues/450 https://github.com/ValvePython/steam/issues/452 known well, but need a lot of changes, will be done later (in another PR)

artur1214 avatar Oct 28 '23 11:10 artur1214

Hey, cant seem to get yours to work. Could you give a login example?

Revibess avatar Oct 29 '23 23:10 Revibess

Hey, cant seem to get yours to work. Could you give a login example?

Of course :)

If you use steam guard:

# AUTH VIA STEAM GUARD CODE
authenticator = SteamAuthenticator(json.load(open('path/to/mafile.mafile')))
auth = WebAuth('login', 'password')
session = auth.login(code=authenticator.get_code())
print(session.cookies)

If you use email:


# AUTH VIA EMAIL CODE
auth = WebAuth('login', 'password')
code_provider_function = auth.login(email_required=True)
code = input('Please, enter your email code here: ')
session = code_provider_function(code)
print(session.cookies)

artur1214 avatar Oct 30 '23 06:10 artur1214

Hey, cant seem to get yours to work. Could you give a login example?

Of course :)

If you use steam guard:

# AUTH VIA STEAM GUARD CODE
authenticator = SteamAuthenticator(json.load(open('path/to/mafile.mafile')))
auth = WebAuth('login', 'password')
session = auth.login(code=authenticator.get_code())
print(session.cookies)

If you use email:

# AUTH VIA EMAIL CODE
auth = WebAuth('login', 'password')
code_provider_function = auth.login(email_required=True)
code = input('Please, enter your email code here: ')
session = code_provider_function(code)
print(session.cookies)

Hi bro, I'm sorry but I simply can not get to work with the demo code using steam guard version. when i invoke the auth.login(code=MY_CODE) method ,it throws:

Traceback (most recent call last): File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 243, in _pollLoginStatus self.refresh_token = resp['response']['refresh_token'] KeyError: 'refresh_token'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Program Files/JetBrains/PyCharm Community Edition 2023.1.2/plugins/python-ce/helpers/pydev/pydevd.py", line 1500, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.2\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\test.py", line 15, in session = auth.login(code=authenticator.get_code()) File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 336, in login self._pollLoginStatus() File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 246, in _pollLoginStatus raise WebAuthException('Authentication requires 2fa token, which is not provided or invalid') steam.webauth.WebAuthException: Authentication requires 2fa token, which is not provided or invalid

kindly can you please help me with this issue, thanks in advance!

cinsin avatar Dec 01 '23 17:12 cinsin

/del

Проблема решена. Это я звонил.

но есть замечание

File "c:\Users\BebraPC\Desktop\steam-py-lib\steam\webauth.py", line 219, in _startSessionWithCredentials self.client_id = resp['response']['client_id'] ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ KeyError: 'client_id'

при некорректных данных было бы лучше выдавать ошибку входа

так же не понятно могу ли я использовать прокси (session.proxies) до установки входа в аккаунта а не после

soshin1337 avatar Dec 09 '23 16:12 soshin1337

path/to/mafile.mafile

Hi, do you have any example to get file path/to/mafile.mafile from steam mobile app?

ChiHangChen avatar Dec 27 '23 09:12 ChiHangChen

Hey, cant seem to get yours to work. Could you give a login example?

Of course :)

If you use steam guard:

# AUTH VIA STEAM GUARD CODE
authenticator = SteamAuthenticator(json.load(open('path/to/mafile.mafile')))
auth = WebAuth('login', 'password')
session = auth.login(code=authenticator.get_code())
print(session.cookies)

If you use email:

# AUTH VIA EMAIL CODE
auth = WebAuth('login', 'password')
code_provider_function = auth.login(email_required=True)
code = input('Please, enter your email code here: ')
session = code_provider_function(code)
print(session.cookies)

Hi bro, I'm sorry but I simply can not get to work with the demo code using steam guard version. when i invoke the auth.login(code=MY_CODE) method ,it throws:

Traceback (most recent call last): File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 243, in _pollLoginStatus self.refresh_token = resp['response']['refresh_token'] KeyError: 'refresh_token' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Program Files/JetBrains/PyCharm Community Edition 2023.1.2/plugins/python-ce/helpers/pydev/pydevd.py", line 1500, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.2\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\test.py", line 15, in session = auth.login(code=authenticator.get_code()) File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 336, in login self._pollLoginStatus() File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 246, in _pollLoginStatus raise WebAuthException('Authentication requires 2fa token, which is not provided or invalid') steam.webauth.WebAuthException: Authentication requires 2fa token, which is not provided or invalid

kindly can you please help me with this issue, thanks in advance!

same error with the email demo

Please, enter your email code here: XXXXX
Traceback (most recent call last):
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 243, in _pollLoginStatus
    self.refresh_token = resp['response']['refresh_token']
KeyError: 'refresh_token'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Administrator\Pictures\Programming\python steambot\main.py", line 7, in <module>
    session = code_provider_function(code)
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 327, in end_login
    self._pollLoginStatus()
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 246, in _pollLoginStatus
    raise WebAuthException('Authentication requires 2fa token, which is not provided or invalid')
steam.webauth.WebAuthException: Authentication requires 2fa token, which is not provided or invalid

Maby make a fork bc this repo looks abandoned.

pawelk1337 avatar Jan 06 '24 13:01 pawelk1337

Hey, cant seem to get yours to work. Could you give a login example?

Of course :)

If you use steam guard:

# AUTH VIA STEAM GUARD CODE
authenticator = SteamAuthenticator(json.load(open('path/to/mafile.mafile')))
auth = WebAuth('login', 'password')
session = auth.login(code=authenticator.get_code())
print(session.cookies)

If you use email:

# AUTH VIA EMAIL CODE
auth = WebAuth('login', 'password')
code_provider_function = auth.login(email_required=True)
code = input('Please, enter your email code here: ')
session = code_provider_function(code)
print(session.cookies)

Hi bro, I'm sorry but I simply can not get to work with the demo code using steam guard version. when i invoke the auth.login(code=MY_CODE) method ,it throws:

Traceback (most recent call last): File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 243, in _pollLoginStatus self.refresh_token = resp['response']['refresh_token'] KeyError: 'refresh_token' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Program Files/JetBrains/PyCharm Community Edition 2023.1.2/plugins/python-ce/helpers/pydev/pydevd.py", line 1500, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.2\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\test.py", line 15, in session = auth.login(code=authenticator.get_code()) File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 336, in login self._pollLoginStatus() File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 246, in _pollLoginStatus raise WebAuthException('Authentication requires 2fa token, which is not provided or invalid') steam.webauth.WebAuthException: Authentication requires 2fa token, which is not provided or invalid

kindly can you please help me with this issue, thanks in advance!

same error with the email demo

Please, enter your email code here: XXXXX
Traceback (most recent call last):
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 243, in _pollLoginStatus
    self.refresh_token = resp['response']['refresh_token']
KeyError: 'refresh_token'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Administrator\Pictures\Programming\python steambot\main.py", line 7, in <module>
    session = code_provider_function(code)
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 327, in end_login
    self._pollLoginStatus()
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 246, in _pollLoginStatus
    raise WebAuthException('Authentication requires 2fa token, which is not provided or invalid')
steam.webauth.WebAuthException: Authentication requires 2fa token, which is not provided or invalid

Maby make a fork bc this repo looks abandoned.

yeah, this repo looks abandoned... :(

VitorOriel avatar Jan 10 '24 17:01 VitorOriel

Hey, cant seem to get yours to work. Could you give a login example?

Of course :)

If you use steam guard:

# AUTH VIA STEAM GUARD CODE
authenticator = SteamAuthenticator(json.load(open('path/to/mafile.mafile')))
auth = WebAuth('login', 'password')
session = auth.login(code=authenticator.get_code())
print(session.cookies)

If you use email:

# AUTH VIA EMAIL CODE
auth = WebAuth('login', 'password')
code_provider_function = auth.login(email_required=True)
code = input('Please, enter your email code here: ')
session = code_provider_function(code)
print(session.cookies)

Hi bro, I'm sorry but I simply can not get to work with the demo code using steam guard version. when i invoke the auth.login(code=MY_CODE) method ,it throws:

Traceback (most recent call last): File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 243, in _pollLoginStatus self.refresh_token = resp['response']['refresh_token'] KeyError: 'refresh_token' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Program Files/JetBrains/PyCharm Community Edition 2023.1.2/plugins/python-ce/helpers/pydev/pydevd.py", line 1500, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.2\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\test.py", line 15, in session = auth.login(code=authenticator.get_code()) File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 336, in login self._pollLoginStatus() File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 246, in _pollLoginStatus raise WebAuthException('Authentication requires 2fa token, which is not provided or invalid') steam.webauth.WebAuthException: Authentication requires 2fa token, which is not provided or invalid

kindly can you please help me with this issue, thanks in advance!

same error with the email demo

Please, enter your email code here: XXXXX
Traceback (most recent call last):
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 243, in _pollLoginStatus
    self.refresh_token = resp['response']['refresh_token']
KeyError: 'refresh_token'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Administrator\Pictures\Programming\python steambot\main.py", line 7, in <module>
    session = code_provider_function(code)
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 327, in end_login
    self._pollLoginStatus()
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 246, in _pollLoginStatus
    raise WebAuthException('Authentication requires 2fa token, which is not provided or invalid')
steam.webauth.WebAuthException: Authentication requires 2fa token, which is not provided or invalid

Maby make a fork bc this repo looks abandoned.

yeah, this repo looks abandoned... :(

lets start over. You receiving code in your email? And this code raises 2fa invalid error? Am I understood you right?

artur1214 avatar Feb 02 '24 08:02 artur1214

Hey, cant seem to get yours to work. Could you give a login example?

Of course :)

If you use steam guard:

# AUTH VIA STEAM GUARD CODE
authenticator = SteamAuthenticator(json.load(open('path/to/mafile.mafile')))
auth = WebAuth('login', 'password')
session = auth.login(code=authenticator.get_code())
print(session.cookies)

If you use email:

# AUTH VIA EMAIL CODE
auth = WebAuth('login', 'password')
code_provider_function = auth.login(email_required=True)
code = input('Please, enter your email code here: ')
session = code_provider_function(code)
print(session.cookies)

Hi bro, I'm sorry but I simply can not get to work with the demo code using steam guard version. when i invoke the auth.login(code=MY_CODE) method ,it throws:

Traceback (most recent call last): File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 243, in _pollLoginStatus self.refresh_token = resp['response']['refresh_token'] KeyError: 'refresh_token' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Program Files/JetBrains/PyCharm Community Edition 2023.1.2/plugins/python-ce/helpers/pydev/pydevd.py", line 1500, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.2\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\test.py", line 15, in session = auth.login(code=authenticator.get_code()) File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 336, in login self._pollLoginStatus() File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 246, in _pollLoginStatus raise WebAuthException('Authentication requires 2fa token, which is not provided or invalid') steam.webauth.WebAuthException: Authentication requires 2fa token, which is not provided or invalid

kindly can you please help me with this issue, thanks in advance!

same error with the email demo

Please, enter your email code here: XXXXX
Traceback (most recent call last):
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 243, in _pollLoginStatus
    self.refresh_token = resp['response']['refresh_token']
KeyError: 'refresh_token'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Administrator\Pictures\Programming\python steambot\main.py", line 7, in <module>
    session = code_provider_function(code)
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 327, in end_login
    self._pollLoginStatus()
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 246, in _pollLoginStatus
    raise WebAuthException('Authentication requires 2fa token, which is not provided or invalid')
steam.webauth.WebAuthException: Authentication requires 2fa token, which is not provided or invalid

Maby make a fork bc this repo looks abandoned.

yeah, this repo looks abandoned... :(

lets start over. You receiving code in your email? And this code raises 2fa invalid error? Am I understood you right?

Why are you using an old function when you added a new one in the update request? 0_o I am new here, so sorry if I misunderstood something.

This code works fine for me and interacts well with Steam Guard. I'm not sure about how to handle the 'mafile' in the code. It seems like others are also unsure about it, so...

auth = wa.WebAuth2("username", "password")
code_provider_function = auth.login()
session = code_provider_function

P. S. Does anyone know if it's possible to save the session between code reloads? If so, how can I do it?

cloudsucker avatar Feb 06 '24 18:02 cloudsucker

@maxfraid To address your postscript, you can have a look at my steam redeemer repo for more info on how to save cookies, but here's the key function:

def export_cookies(cookie_file, session):
    try:
        cookies = None
        if type(session) is requests.Session:
            # handle Steam session
            cookies = session.cookies
        pickle.dump(cookies, open(cookie_file,"wb"))
        return True
    except:
        return False

FailSpy avatar Mar 01 '24 18:03 FailSpy

Hey, cant seem to get yours to work. Could you give a login example?

Of course :)

If you use steam guard:

# AUTH VIA STEAM GUARD CODE
authenticator = SteamAuthenticator(json.load(open('path/to/mafile.mafile')))
auth = WebAuth('login', 'password')
session = auth.login(code=authenticator.get_code())
print(session.cookies)

If you use email:

# AUTH VIA EMAIL CODE
auth = WebAuth('login', 'password')
code_provider_function = auth.login(email_required=True)
code = input('Please, enter your email code here: ')
session = code_provider_function(code)
print(session.cookies)

Hi bro, I'm sorry but I simply can not get to work with the demo code using steam guard version. when i invoke the auth.login(code=MY_CODE) method ,it throws:

Traceback (most recent call last): File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 243, in _pollLoginStatus self.refresh_token = resp['response']['refresh_token'] KeyError: 'refresh_token' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Program Files/JetBrains/PyCharm Community Edition 2023.1.2/plugins/python-ce/helpers/pydev/pydevd.py", line 1500, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1.2\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\test.py", line 15, in session = auth.login(code=authenticator.get_code()) File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 336, in login self._pollLoginStatus() File "D:\tmp\test-webauth\steam-py-lib-web_uth_new_api_fix\steam\webauth.py", line 246, in _pollLoginStatus raise WebAuthException('Authentication requires 2fa token, which is not provided or invalid') steam.webauth.WebAuthException: Authentication requires 2fa token, which is not provided or invalid

kindly can you please help me with this issue, thanks in advance!

same error with the email demo

Please, enter your email code here: XXXXX
Traceback (most recent call last):
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 243, in _pollLoginStatus
    self.refresh_token = resp['response']['refresh_token']
KeyError: 'refresh_token'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Administrator\Pictures\Programming\python steambot\main.py", line 7, in <module>
    session = code_provider_function(code)
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 327, in end_login
    self._pollLoginStatus()
  File "C:\Users\Administrator\Pictures\Programming\python steambot\steam\webauth.py", line 246, in _pollLoginStatus
    raise WebAuthException('Authentication requires 2fa token, which is not provided or invalid')
steam.webauth.WebAuthException: Authentication requires 2fa token, which is not provided or invalid

Maby make a fork bc this repo looks abandoned.

yeah, this repo looks abandoned... :(

lets start over. You receiving code in your email? And this code raises 2fa invalid error? Am I understood you right?

Why are you using an old function when you added a new one in the update request? 0_o I am new here, so sorry if I misunderstood something.

This code works fine for me and interacts well with Steam Guard. I'm not sure about how to handle the 'mafile' in the code. It seems like others are also unsure about it, so...

auth = wa.WebAuth2("username", "password")
code_provider_function = auth.login()
session = code_provider_function

P. S. Does anyone know if it's possible to save the session between code reloads? If so, how can I do it?

hi bro, could you give an example of code for generating a mafile, I’m just starting to understand this and would be very happy with any help

Bahrain-bag avatar Aug 04 '24 20:08 Bahrain-bag