philippj / SteamworksPy

A working Python API system for Valve's Steamworks.
MIT License
212 stars 39 forks source link

GetAuthSessionTicket() produces invalid tickets #94

Open henrydatei opened 1 year ago

henrydatei commented 1 year ago

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 commented 1 year ago

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

henrydatei commented 1 year ago

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: https://github.com/philippj/SteamworksPy/issues/88#issuecomment-1563181860

henrydatei commented 1 year ago

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 commented 11 months ago

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 commented 11 months ago

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