Hello everyone,
I am using Unity Authentication to prepare a login connected to Steam.
Unfortunately I am receiving this error when trying to use SignInWithSteamAsync
[Authentication]: Request failed: 401, {"detail":"invalid token","details":[ ],"status":401,"title":"PERMISSION_DENIED"}, request-id: 33012a6a-73db-45dc-a5e6-695eec5edc04
This is roughly my implementation so far:
using System;
using System.Threading.Tasks;
using Steamworks;
using Unity.Services.Authentication;
using Unity.Services.Core;
public class LoginManager : BaseBehaviour
{
Callback<GetTicketForWebApiResponse_t> m_AuthTicketForWebApiResponseCallback;
string sessionTicket;
string identity = "unityauthenticationservice";
public override async void Init(BaseBehaviour parent = null)
{
base.Init(parent);
await SettingsSingleton.Instance.InitUGC();
#if ENABLESTEAMWORKS
SteamManager.Instance.Init(this);
SignInWithSteam();
#else
if (!AuthenticationService.Instance.IsSignedIn)
await SignInAnonymouslyAsync();
#endif
}
#if ENABLESTEAMWORKS
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);
}
async void OnAuthCallback(GetTicketForWebApiResponse_t callback)
{
sessionTicket = BitConverter.ToString(callback.m_rgubTicket).Replace("-", string.Empty);
m_AuthTicketForWebApiResponseCallback.Dispose();
m_AuthTicketForWebApiResponseCallback = null;
sos.logging.Logger.Debug("Steam Login success. Session Ticket: " + sessionTicket, sos.logging.DebugKey.AUTHENTICATION);
// Call Unity Authentication SDK to sign in or link with Steam
await SignInWithSteamAsync(sessionTicket,identity);
}
async Task SignInWithSteamAsync(string ticket, string identity)
{
try
{
await AuthenticationService.Instance.SignInWithSteamAsync(ticket, identity);
sos.logging.Logger.Debug("Steam SignIn is successful.", sos.logging.DebugKey.AUTHENTICATION);
}
catch (AuthenticationException ex)
{
// Compare error code to AuthenticationErrorCodes
// Notify the player with the proper error message
sos.logging.Logger.Warn(ex.ToString(), sos.logging.DebugKey.AUTHENTICATION);
}
catch (RequestFailedException ex)
{
// Compare error code to CommonErrorCodes
// Notify the player with the proper error message
sos.logging.Logger.Warn(ex.ToString(), sos.logging.DebugKey.AUTHENTICATION);
}
}
#endif
async Task SignInAnonymouslyAsync()
{
try
{
await AuthenticationService.Instance.SignInAnonymouslyAsync();
sos.logging.Logger.Debug("Sign in anonymously succeeded!", sos.logging.DebugKey.AUTHENTICATION);
// Shows how to get the playerID
sos.logging.Logger.Debug($"PlayerID: {AuthenticationService.Instance.PlayerId}", sos.logging.DebugKey.AUTHENTICATION);
}
catch (AuthenticationException ex)
{
// Compare error code to AuthenticationErrorCodes
// Notify the player with the proper error message
sos.logging.Logger.Error(ex.ToString(), sos.logging.DebugKey.AUTHENTICATION);
}
catch (RequestFailedException ex)
{
// Compare error code to CommonErrorCodes
// Notify the player with the proper error message
sos.logging.Logger.Error(ex.ToString(), sos.logging.DebugKey.AUTHENTICATION);
}
}
}
I am sure that AppId in both UGS portal and steam_appid.txt are correct.
I am receiving a session ticket correctly:
[Debug][AUTHENTICATION]: Steam Login success. Session Ticket: 14000000EC417B107478BC0C1FD014020100100182068765180000000100000005000000E7183227682E9569CD3FFC0B08000000B200000032000000040000001FD0140201001001C8C618003105285D3401A8C00000000015147B6595C396 etc etc
I am using Steamworks SDK 20.2.0 (latest) and Unity 2022.3.9f1. So far this was tested only in editor.
Please let me know what else I could check.
Thanks in advance.