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

GetAuthSessionTicket() produces invalid tickets #94

Open
henrydatei opened this issue Aug 9, 2023 · 5 comments
Open

GetAuthSessionTicket() produces invalid tickets #94

henrydatei opened this issue Aug 9, 2023 · 5 comments

Comments

@henrydatei
Copy link

I tried to validate a ticket produces by GetAuthSessionTicket(). But Steam says that the ticket is invalid. I used the following code and I'm using Ubuntu 22.04 LTS.

from steamworks import STEAMWORKS
st = STEAMWORKS()
st.initialize()
auth_token = st.Users.GetAuthSessionTicket()
player_id = st.Users.GetSteamID()
player_name = st.Friends.GetPlayerName().decode('utf-8')
friends = ",".join([str(st.Friends.GetFriendByIndex(i)) for i in range(st.Friends.GetFriendCount())])
print(auth_token)
print(player_id)
print(player_name)
print(friends)

params = {
    "key": "YOUR KEY", # see it on https://steamcommunity.com/dev/apikey
    "appid": "480",
    "ticket": auth_token
}
r = requests.get("https://api.steampowered.com/ISteamUserAuth/AuthenticateUserTicket/v1/", params=params)
print(r.json())

Steam returns

{'response': {'error': {'errorcode': 101, 'errordesc': 'Invalid ticket'}}}

I used the AppID 480 also in the file steam_appid.txt. Do I do something wrong?

@philippj
Copy link
Owner

philippj commented Aug 9, 2023

ISteamUserAuth/AuthenticateUserTicket is a partner only API endpoint which requires a partner API key: https://partner.steamgames.com/doc/webapi/ISteamUserAuth

@henrydatei
Copy link
Author

henrydatei commented Aug 9, 2023

They say that the web api api.steampowered.com has such a function too (https://partner.steamgames.com/doc/webapi/ISteamUserAuth)

But I think I use the Steamworks SDK 155 (157 is the current one I think, but it didn't compile and I read somewhere that I should use 155 instead). Maybe Steam has changed something with the ticket generation

EDIT: Here I've seen it: #88 (comment)

@henrydatei
Copy link
Author

Today I tried to use the SDK 157 where compiling fails with

g++ -std=c++11 -o SteamworksPy.so -shared -fPIC SteamworksPy.cpp -l steam_api -L.
SteamworksPy.cpp: In function ‘int GetAuthSessionTicket(char*)’:
SteamworksPy.cpp:987:38: error: no matching function for call to ‘ISteamUser::GetAuthSessionTicket(char*&, int, uint32*)’
  987 |     SteamUser()->GetAuthSessionTicket(buffer, 1024, &size);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from sdk/steam/steam_api.h:25,
                 from SteamworksPy.cpp:16:
sdk/steam/isteamuser.h:131:29: note: candidate: ‘virtual HAuthTicket ISteamUser::GetAuthSessionTicket(void*, int, uint32*, const SteamNetworkingIdentity*)’
  131 |         virtual HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket, const SteamNetworkingIdentity *pSteamNetworkingIdentity ) = 0;
      |                             ^~~~~~~~~~~~~~~~~~~~
sdk/steam/isteamuser.h:131:29: note:   candidate expects 4 arguments, 3 provided
make: *** [Makefile:2: makeall] Fehler 1

So I changed the function GetAuthSessionTicket() (https://github.com/philippj/SteamworksPy/blob/master/library/SteamworksPy.cpp#L982) to

// Returns the info needed to obtain a Session Ticket.
SW_PY int GetAuthSessionTicket(char* buffer) {
    if (SteamUser() == NULL) {
        return 0;
    }
    uint32 size{};
    SteamNetworkingIdentity identity;
    SteamUser()->GetAuthSessionTicket(buffer, 1024, &size, &identity);
    return size;
}

To be honest this change was suggested by ChatGPT, I'm pretty clueless when it comes to C++ but after that change compiling works. Unfortunately the inital error of producing an invalid ticket still remains.

@twstagg
Copy link

twstagg commented Oct 2, 2023

Today I tried to use the SDK 157 where compiling fails with

g++ -std=c++11 -o SteamworksPy.so -shared -fPIC SteamworksPy.cpp -l steam_api -L.
SteamworksPy.cpp: In function ‘int GetAuthSessionTicket(char*)’:
SteamworksPy.cpp:987:38: error: no matching function for call to ‘ISteamUser::GetAuthSessionTicket(char*&, int, uint32*)’
  987 |     SteamUser()->GetAuthSessionTicket(buffer, 1024, &size);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from sdk/steam/steam_api.h:25,
                 from SteamworksPy.cpp:16:
sdk/steam/isteamuser.h:131:29: note: candidate: ‘virtual HAuthTicket ISteamUser::GetAuthSessionTicket(void*, int, uint32*, const SteamNetworkingIdentity*)’
  131 |         virtual HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket, const SteamNetworkingIdentity *pSteamNetworkingIdentity ) = 0;
      |                             ^~~~~~~~~~~~~~~~~~~~
sdk/steam/isteamuser.h:131:29: note:   candidate expects 4 arguments, 3 provided
make: *** [Makefile:2: makeall] Fehler 1

So I changed the function GetAuthSessionTicket() (https://github.com/philippj/SteamworksPy/blob/master/library/SteamworksPy.cpp#L982) to

// Returns the info needed to obtain a Session Ticket.
SW_PY int GetAuthSessionTicket(char* buffer) {
    if (SteamUser() == NULL) {
        return 0;
    }
    uint32 size{};
    SteamNetworkingIdentity identity;
    SteamUser()->GetAuthSessionTicket(buffer, 1024, &size, &identity);
    return size;
}

To be honest this change was suggested by ChatGPT, I'm pretty clueless when it comes to C++ but after that change compiling works. Unfortunately the inital error of producing an invalid ticket still remains.

This is interesting.

I was actually taking a look at updating this since I am somewhat familiar with the code at this point RE: #91

I will take a look at implementing the change needed for SteamworksPy to be compatible with SDK 157 and onward.

@henrydatei
Copy link
Author

Thanks for taking a look into the code. Hopefully my issue resolves then

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

3 participants