Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login with cookie #422

Open
yeqwer opened this issue Dec 24, 2024 · 27 comments
Open

Login with cookie #422

yeqwer opened this issue Dec 24, 2024 · 27 comments

Comments

@yeqwer
Copy link

yeqwer commented Dec 24, 2024

Does logging in via cookies work?
If so, what should the cookie data look like?
My goal is to log into an account with only a refresh token. Thanks for any information :D

@yeqwer
Copy link
Author

yeqwer commented Dec 24, 2024

Unfortunately this solution doesn't work.

@yeqwer
Copy link
Author

yeqwer commented Dec 24, 2024

Maybe I can log in not directly with refresh token, but with cookies, which I will get with steam-session module for node js from DoctorMcKay. But I would like to know which cookie dict I should give.

@bukson
Copy link
Owner

bukson commented Dec 25, 2024

SteamClient supports login_cookies parameter, that allows login by cookies

@delta325
Copy link

delta325 commented Dec 25, 2024

I'm experiencing the same problem, login with cookies method works fine, but the session dies after 24 hours and you have to login again. It creates another device in the list of authorized devices and if you are unlucky as me, you will get your account locked when you'll try to make_offer_with_url method (steam says it suspects account was stolen, lol)

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

My problem is that i want to login with cookie but i don't know how cookie dict should look like. i would be very grateful if you show an example of cookie dict. I understand that if i login using steamid, shared_secret, identity_secret and then save cookie and login with cookie in future, it will work. But i don't want to use shared_secret and identity_secret.

@delta325
Copy link

delta325 commented Dec 25, 2024

My problem is that i want to login with cookie but i don't know how cookie dict should look like. i would be very grateful if you show an example of cookie dict. I understand that if i login using steamid, shared_secret, identity_secret and then save cookie and login with cookie in future, it will work. But i don't want to use shared_secret and identity_secret.

My cookies dict looks like this

{"sessionid": "xxxxxxxxxxx", "steamCountry": "xxxxxxxxxxx", "steamLoginSecure": "xxxxxxxxxxxx", "steamRefresh_steam": "xxxxxxxxxxxxxx"}

The problem is that they last only 24 hours.
Do you have any idea how to login without creating new device everyday?

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

Моя проблема в том, что я хочу войти с помощью cookie, но не знаю, как должен выглядеть cookie dict. Я был бы очень признателен, если бы вы показали пример cookie dict. Я понимаю, что если я войду, используя steamid, shared_secret, identity_secret, а затем сохраню cookie и войду с cookie в будущем, это сработает. Но я не хочу использовать shared_secret и identity_secret.

Мой словарь cookie выглядит так {"sessionid": "xxxxxxxxxxx", "steamCountry": "xxxxxxxxxxx", "steamLoginSecure": "xxxxxxxxxxxx", "steamRefresh_steam": "xxxxxxxxxxxxxx"} Проблема в том, что они существуют всего 24 часа. Есть ли у вас идеи, как войти в систему, не создавая новое устройство каждый день?

As far as I know a session for 24 hours is refreshed with refresh_token, and you can refresh it in the module for node.js I mentioned above or you can refresh it manually :D

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

I don't know about adding a new device, nor do I know what's wrong with it or how to avoid it. I think that's how steam works.

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

Моя проблема в том, что я хочу войти с помощью cookie, но не знаю, как должен выглядеть cookie dict. Я был бы очень признателен, если бы вы показали пример cookie dict. Я понимаю, что если я войду, используя steamid, shared_secret, identity_secret, а затем сохраню cookie и войду с cookie в будущем, это сработает. Но я не хочу использовать shared_secret и identity_secret.

Мой словарь cookie выглядит так

{"sessionid": "xxxxxxxxxxx", "steamCountry": "xxxxxxxxxxx", "steamLoginSecure": "xxxxxxxxxxxx", "steamRefresh_steam": "xxxxxxxxxxxxxxx"}

Проблема в том, что они длятся всего 24 часа. Есть ли у вас идеи, как войти, не создавая новое устройство каждый день?

And you got those dictionary cookies just from your browser?

@delta325
Copy link

Моя проблема в том, что я хочу войти с помощью cookie, но не знаю, как должен выглядеть cookie dict. Я был бы очень признателен, если бы вы показали пример cookie dict. Я понимаю, что если я войду, используя steamid, shared_secret, identity_secret, а затем сохраню cookie и войду с cookie в будущем, это сработает. Но я не хочу использовать shared_secret и identity_secret.

Мой словарь cookie выглядит так {"sessionid": "xxxxxxxxxxx", "steamCountry": "xxxxxxxxxxx", "steamLoginSecure": "xxxxxxxxxxxx", "steamRefresh_steam": "xxxxxxxxxxxxxx"} Проблема в том, что они существуют всего 24 часа. Есть ли у вас идеи, как войти в систему, не создавая новое устройство каждый день?

As far as I know a session for 24 hours is refreshed with refresh_token, and you can refresh it in the module for node.js I mentioned above or you can refresh it manually :D

Yes, I've already read about node. js, maybe we can implement their solution here in Python

@delta325
Copy link

Моя проблема в том, что я хочу войти с помощью cookie, но не знаю, как должен выглядеть cookie dict. Я был бы очень признателен, если бы вы показали пример cookie dict. Я понимаю, что если я войду, используя steamid, shared_secret, identity_secret, а затем сохраню cookie и войду с cookie в будущем, это сработает. Но я не хочу использовать shared_secret и identity_secret.

Мой словарь cookie выглядит так
{"sessionid": "xxxxxxxxxxx", "steamCountry": "xxxxxxxxxxx", "steamLoginSecure": "xxxxxxxxxxxx", "steamRefresh_steam": "xxxxxxxxxxxxxxx"}
Проблема в том, что они длятся всего 24 часа. Есть ли у вас идеи, как войти, не создавая новое устройство каждый день?

And you got those dictionary cookies just from your browser?

No, you can get your cookies after you login with client.login method and then obtain your cookies with client._session.cookies.get_dict("steamcommunity") method

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

But I don't want to use shared_secret and identity_secret for login. I would like to log in immediately with a cookie.

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

Моя проблема в том, что я хочу войти с помощью cookie, но не знаю, как должен выглядеть cookie dict. Я был бы очень признателен, если бы вы показали пример cookie dict. Я понимаю, что если я войду, используя steamid, shared_secret, identity_secret, а затем сохраню cookie и войду с cookie в будущем, это сработает. Но я не хочу использовать shared_secret и identity_secret.

Мой словарь cookie выглядит так {"sessionid": "xxxxxxxxxxx", "steamCountry": "xxxxxxxxxxx", "steamLoginSecure": "xxxxxxxxxxxx", "steamRefresh_steam": "xxxxxxxxxxxxxx"} Проблема в том, что они существуют всего 24 часа. Есть ли у вас идеи, как войти в систему, не создавая новое устройство каждый день?

As far as I know a session for 24 hours is refreshed with refresh_token, and you can refresh it in the module for node.js I mentioned above or you can refresh it manually :D

Yes, I've already read about node. js, maybe we can implement their solution here in Python

I don't know exactly how the update works. But I do know that this module works very well and I suggest you to look at its code.
I would use only this node.js module myself, but it doesn't have an item purchase function. I've been trying to write add-ons to this module, but I haven't finished yet.

@delta325
Copy link

But I don't want to use shared_secret and identity_secret for login. I would like to log in immediately with a cookie.

You can login without shared_secret as I said, I meant if you want to obtain cookies you will have to use shared_secret.
If you already have cookies, you can login with you api_key and username and you cookies (there is a method for it)

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

I'm running to try it! :D

@delta325
Copy link

delta325 commented Dec 25, 2024

I'm running to try it! :D

I wish you a good luck.
Small tip from me: if you'll login with only cookies, you won't be able to confirm trades, and some exceptions may occur. You will have to catch them.

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

Бегу пробовать! :D

Желаю вам удачи. Небольшой совет от меня: если вы войдете только с куками, вы не сможете подтверждать сделки, и могут возникнуть некоторые исключения. Вам придется их ловить.

Thanks for the tip, I thought I had to confirm, but I only need to buy items ;D

@bukson
Copy link
Owner

bukson commented Dec 25, 2024

If someone can implement refresh cookie method, I will gladly merge it and release new version.

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

Unfortunately I get an error of this format when I use my cookies from my browser:

Traceback (most recent call last): File "/Users/yeqwer/Projects/steam_sculp/steam_controller_py/login2.py", line 18, in <module> client = SteamClient(api_key=API_KEY, username=USER_NAME, login_cookies=LOGIN_COOKIES) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/yeqwer/.pyenv/versions/3.12.7/envs/steam-sculp/lib/python3.12/site-packages/steampy/client.py", line 61, in __init__ self.set_login_cookies(login_cookies) File "/Users/yeqwer/.pyenv/versions/3.12.7/envs/steam-sculp/lib/python3.12/site-packages/steampy/client.py", line 79, in set_login_cookies self.steam_guard = {'steamid': str(self.get_steam_id())} ^^^^^^^^^^^^^^^^^^^ File "/Users/yeqwer/.pyenv/versions/3.12.7/envs/steam-sculp/lib/python3.12/site-packages/steampy/utils.py", line 26, in func_wrapper return func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/yeqwer/.pyenv/versions/3.12.7/envs/steam-sculp/lib/python3.12/site-packages/steampy/client.py", line 88, in get_steam_id raise ValueError(f'Invalid steam_id: {steam_id}') ValueError: Invalid steam_id: None

I used the code from the example in the documentation:

from steampy.client import SteamClient from dotenv import load_dotenv import os

load_dotenv()
 
API_KEY = os.getenv("API_KEY") USER_NAME = os.getenv("USER_NAME") LOGIN_COOKIES = { "sessionid": os.getenv("sessionid"), "steamCounry": os.getenv("steamCountry"), "steamLoginSecure": os.getenv("steamLoginSecure"), "steamRefresh_steam": os.getenv("steamRefresh_steam") }

client = SteamClient(api_key=API_KEY, username=USER_NAME, login_cookies=LOGIN_COOKIES)

print(client.was_login_executed)

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

I have seen a similar error discussed in issues github, but haven't found a solution. Maybe I'm using the wrong cookie format?
@bukson

@delta325
Copy link

I have seen a similar error discussed in issues github, but haven't found a solution. Maybe I'm using the wrong cookie format? @bukson

Are you sure you use cookies from correct account?
There must be your steam_id there, compare them

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

I have seen a similar error discussed in issues github, but haven't found a solution. Maybe I'm using the wrong cookie format? @bukson

Are you sure you use cookies from correct account? There must be your steam_id there, compare them

steamid is absolutely accurate. As I understand it steamLoginSecure consists of steamid + access_token

@delta325
Copy link

I have seen a similar error discussed in issues github, but haven't found a solution. Maybe I'm using the wrong cookie format? @bukson

Are you sure you use cookies from correct account? There must be your steam_id there, compare them

steamid is absolutely accurate. As I understand it steamLoginSecure consists of steamid + access_token

I load my cookies as a json file and it works. The problem is in your code I guess. And make sure you use cookies from steamcommunity, not the steam.powered

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

I load my cookies as a json file and it works. The problem is in your code I guess. And make sure you use cookies from steamcommunity, not the steam.powered

You're right, I fixed that error, but when I buy a buy item, an error pops up that says I must use the login method. Am I correct that cookie login does not support buying items?

@yeqwer
Copy link
Author

yeqwer commented Dec 25, 2024

I've seen an implementation of buying items where the person only gives a refresh_token. How did you implement it... :D

@delta325
Copy link

I load my cookies as a json file and it works. The problem is in your code I guess. And make sure you use cookies from steamcommunity, not the steam.powered

You're right, I fixed that error, but when I buy a buy item, an error pops up that says I must use the login method. Am I correct that cookie login does not support buying items?

I use Steampy only to accept and to send trades, I didn't work with buying items xD
You can read docs if something is unclear

@yeqwer
Copy link
Author

yeqwer commented Dec 27, 2024

I use Steampy only to accept and to send trades, I didn't work with buying items xD You can read docs if something is unclear

The documentation says exactly that I should use the .login() method before purchasing.
That said, I'm definitely logged into the account, just like with shared and identity, but I can't buy items.

Can you please tell me if this is possible or not? @bukson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@bukson @yeqwer @delta325 and others