I want to authenticate Unity game client with Steamworks.net to connect account with my Node.js server by using SteamUser.GetAuthTicketForWebApi. Howhever I cannot get a callback from that function. In my code example Debug.Log("callback") never appear. Commands like SteamUser.GetSteamID() or SteamFriends.GetPersonaName() are working correctly. But not SteamUser.GetAuthTicketForWebApi.
I tried to do this on a newly created project. All steps i have done, Should I have done something else?:
- new project
- adding authentication in package manager
- set up App Id and Key in Authentication project settings
- adding steamworks.net in package manager
- setting up my app id in steam_appid.txt
- add game object with SteamManager.cs in scene
- add game object with that code:
using Steamworks;
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Services.Authentication;
using Unity.Services.Core;
using UnityEngine;
public class SteamUtility : MonoBehaviour
{
Callback<GetTicketForWebApiResponse_t> m_AuthTicketForWebApiResponseCallback;
string m_SessionTicket;
string identity = "unityauthenticationservice";
private void Start()
{
SignInWithSteam();
}
void SignInWithSteam()
{
// It's not necessary to add event handlers if they are
// already hooked up.
// Callback.Create return value must be assigned to a
// member variable to prevent the GC from cleaning it up.
// Create the callback to receive events when the session ticket
// is ready to use in the web API.
// See GetAuthSessionTicket document for details.
m_AuthTicketForWebApiResponseCallback = Callback<GetTicketForWebApiResponse_t>.Create(OnAuthCallback);
SteamUser.GetAuthTicketForWebApi(identity);
Debug.Log("login");
}
void OnAuthCallback(GetTicketForWebApiResponse_t callback)
{
Debug.Log("callback");
m_SessionTicket = BitConverter.ToString(callback.m_rgubTicket).Replace("-", string.Empty);
m_AuthTicketForWebApiResponseCallback.Dispose();
m_AuthTicketForWebApiResponseCallback = null;
Debug.Log("Steam Login success. Session Ticket: " + m_SessionTicket);
// Call Unity Authentication SDK to sign in or link with Steam, displayed in the following examples, using the same identity string and the m_SessionTicket.
}
}