question

Dylan Hunt avatar image
Dylan Hunt asked

Is there an example to connect PlayFab to Steam via Steamworks.NET?

[Updated OP] In reference to this old post, I'm struggling obtaining a correct Steam access token:

  1. I added my steamapp id (used an online hex converter) + web api key found in steamworks "manage groups" >> "<game> group" section) to PlayFab on the addon dash
  2. I am using a working Steamworks.NET with Unity 5.5
  3. I attempted to follow this example.
  4. Results are the following with both POSTman and C# code (PlayFab code in comments):
{
  "code": 400,
  "status": "BadRequest",
  "error": "InvalidSteamTicket",
  "errorCode": 1010,
  "errorMessage": "Steam WebAPI error: 102 (Ticket for other app)"
}

5. Steam code to get ticket (EDITED: confirmed 100% working as hex/string since it works fine on GameSp*rks that has same requirements). It must be an issue with the hex app id or something?:

// Start
ticketBlob = new byte[1024];

// Retrieve ticket; hTicket should be a field in the class so you can use it to cancel the ticket later
// When you pass an object, the object can be modified by the callee. This function modifies the byte array you've passed to it.
hTicket = SteamUser.GetAuthSessionTicket(ticketBlob, ticketBlob.Length, out ticketSize);

// Resize the buffer to actual length
Array.Resize(ref ticketBlob, (int)ticketSize);

// Convert bytes to string
StringBuilder sb = new StringBuilder();
foreach (byte b in ticketBlob)
{
    sb.AppendFormat("{0:x2}", b);
}
hexTicket = sb.ToString();
Debug.Log("[STEAM] hexTicket == " + hexTicket);

// Wait for callback =>
// Sample expired ticket:
1400000096a8a5169ad90a36748a1f0001001001aed8bc58180000000100000002000000d52bb0b4000000001a97f00934000000b20000003200000004000000748a1f000100100150150900d52bb0b41901a8c0000000003115b958b1c4d4580100545f020000000000845f3c411223ae504089bb36dc0c40196115a84cea06c811f03e72dae3fd35681f9c757234cda77ff40974c7fd7a2973522d650e9e90a3031644626e307094f724a4de4686b7683b1ffd70d76803950e41a9f7bb261e29c5072513cab35a0c4fab59ae1a9ea17c6b82f41f32c0bd1a1790fe687c2662884c9d4b5ee25436d821
sdks
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Dylan Hunt avatar image
Dylan Hunt answered

EDIT: WORKING in 4 steps!

1. Ensure your Steamworks.NET root .txt file shows YOUR app id, and not the default.

2. Your VANILLA app id. Throughout the forum it's stated "hex app id" -- nope, it's your regular one. This must have been ninja changed.

3. As for the app keys ... it's not just any "web api key", it's the one specifically on the "manage groups" page (Brendan informed me via email) - a different API key than the one at the root level of your steamworks.

4. The steamworks.NET code is below:

(Confirmed working directly from STEAMWORKS.NET dev):

byte[] ticketBlob = new byte[1024];
uint ticketSize;

// Retrieve ticket; hTicket should be a field in the class so you can use it to cancel the ticket later
// When you pass an object, the object can be modified by the callee. This function modifies the byte array you've passed to it.
HAuthTicket hTicket = SteamUser.GetAuthSessionTicket(ticketBlob, ticketBlob.Length, out ticketSize);

// Resize the buffer to actual length
Array.Resize(ref ticketBlob, (int)ticketSize);

// Convert bytes to string
StringBuilder sb = new StringBuilder();
foreach (byte b in ticketBlob)
{
	sb.AppendFormat("{0:x2}", b);
}
string hexTicket = sb.ToString();

// ...

// Cancel ticket when your session is complete
SteamUser.CancelAuthTicket(hTicket);
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image brendan ♦♦ commented ·

Great, glad it's working for you now. I'll put in a backlog item to get the specifics on the App ID called out on that page, and I'll have a look through the forums for where hexadecimal is still mentioned (it used to be the case that you had to enter it as a hex value).

0 Likes 0 ·
brendan avatar image
brendan answered

Can you include the code that shows how you're using the Auth Session Ticket in the call to LoginWithSteam? Also, can you include the complete error response from PlayFab, with the error details? The most common issue is not converting the ticket into a string as described in the documentation (https://api.playfab.com/Documentation/Client/method/LoginWithSteam). What you get from Steam is a byte array. It must be converted to a string, so if the first three bytes are 0x43, 0xa9, and 0x03, the first six characters of the string would be "43a903".

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Dylan Hunt avatar image Dylan Hunt commented ·
public void LoginWithSteam(Action<LoginResult> callbackRes, Action<PlayFabError> callbackErr)
{
    Debug.Log("[PF] @ LoginWithSteam");
    LoginWithSteamRequest request = new LoginWithSteamRequest()
    {
        TitleId = PLAYFAB_TITLE_ID,
        SteamTicket = s_SteamManager.GetAuthSessionTicket(), // << HERE
        CreateAccount = false,
        InfoRequestParameters = GetInfoRequestParams()
    };


    PlayFabClientAPI.LoginWithSteam(request, (result) =>
    {
        PlayFabId = result.PlayFabId;
        Debug.Log("[PF] LOGGED IN via LoginWithSteam (SteamAuthSessionTicket)! Got PlayFabID: " + PlayFabId);


        // Post-events after logging in successfully
        LoginResultPost(result, callbackRes);
    },
    (error) =>
    {
        Debug.Log("[PF] **ERR registering player with Steam: " + error);


        // Done
        if (callbackErr != null)
            callbackErr(error);
    });
}

Did you see the attached screenshot of the results? I was curious:

  • m_HAuthTicket seems to be increasing by 1 each request. This is right?
  • m_pcbTicket seems to be a 3-digit number. It does't look "Hexxy"..
0 Likes 0 ·
brendan avatar image brendan ♦♦ Dylan Hunt commented ·

I really can't speak to those two parameters, as they're Steam-specific, and unrelated to our sign-in process. The code above appears to show passing the Steam auth ticket to our login call as-is, which won't work, however. You need to convert it to a string, as described above.

0 Likes 0 ·
Dylan Hunt avatar image Dylan Hunt brendan ♦♦ commented ·

My mind is still blown about this -- I can't figure it out -- the code example only shows the length and the byte ticket. How do you "convert it to a string"?

"so if the first three bytes are 0x43, 0xa9, and 0x03, the first six characters of the string would be "43a903""

When I do m_HAuthTIcket.ToString() the result of m_pcbTicket is 234, which I'm told is the length that you mentioned you need.

m_Ticket I'm told is the actual ticket, but in the example it doesn't seem like it's actually changed - ever. Seems like it's just an empty Byte 1024 in size.

If anyone can come up with a code snippet before I figure this out or my Steamworks post figures it out, I'll give $10 paypal - I think these instructions are old or I'm looking at the wrong thing. Or I'm just really bad at this :P Whoever gives the code snippet, pls post it on the docs so others can not get as stumped as I do (since most people probably use Steamworks.NET if they are using Unity)

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.