Steam Authentification not working

Hello,

I am using Authentification with Steam and I am getting a successful steam login session ticket through the SignInWithSteam() method, but when I try to link the Unity UGS Authentification by using SignInWithSteamAsync(string ticket) I get the following errors:

[Authentication]: Request completed with error: {“title”:“PERMISSION_DENIED”,“detail”:“unable to validate token”,“details”:[ ],“status”:401}
UnityEngine.Logger:LogWarning (string,object)
Unity.Services.Authentication.Logger:LogWarning (object) (at Library/PackageCache/com.unity.services.authentication@2.1.1/Runtime/Utilities/Logger.cs:17)
Unity.Services.Authentication.WebRequest:RequestCompleted (System.Threading.Tasks.TaskCompletionSource1<string>,long,bool,bool,string,string,System.Collections.Generic.IDictionary2<string, string>) (at Library/PackageCache/com.unity.services.authentication@2.1.1/Runtime/Network/WebRequest.cs:193)
Unity.Services.Authentication.WebRequest/<>c__DisplayClass15_0:b__0 (UnityEngine.AsyncOperation) (at Library/PackageCache/com.unity.services.authentication@2.1.1/Runtime/Network/WebRequest.cs:75)
UnityEngine.AsyncOperation:InvokeCompletionEvent ()

WebRequestException: {“title”:“PERMISSION_DENIED”,“detail”:“unable to validate token”,“details”:[ ],“status”:401}
Unity.Services.Authentication.WebRequest.SendAsync[T] () (at Library/PackageCache/com.unity.services.authentication@2.1.1/Runtime/Network/WebRequest.cs:44)
Unity.Services.Authentication.AuthenticationServiceInternal.HandleSignInRequestAsync (System.Func1[TResult] signInRequest, System.Boolean enableRefresh) (at Library/PackageCache/com.unity.services.authentication@2.1.1/Runtime/AuthenticationServiceInternal.cs:451) Rethrow as AuthenticationException: unable to validate token Unity.Services.Authentication.AuthenticationServiceInternal.HandleSignInRequestAsync (System.Func1[TResult] signInRequest, System.Boolean enableRefresh) (at Library/PackageCache/com.unity.services.authentication@2.1.1/Runtime/AuthenticationServiceInternal.cs:463)
SteamAuth.SignInWithSteamAsync (System.String ticket) (at Assets/SteamAuth.cs:93)
UnityEngine.Debug:LogException(Exception)
d__9:MoveNext() (at Assets/SteamAuth.cs:101)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetException(Exception)
Unity.Services.Authentication.d__101:MoveNext() (at Library/PackageCache/com.unity.services.authentication@2.1.1/Runtime/AuthenticationServiceInternal.cs:463)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetException(Exception) Unity.Services.Authentication.<SendAsync>d__141:MoveNext() (at Library/PackageCache/com.unity.services.authentication@2.1.1/Runtime/Network/WebRequest.cs:62)
System.Threading.Tasks.TaskCompletionSource1:SetException(Exception) Unity.Services.Authentication.WebRequest:RequestCompleted(TaskCompletionSource1, Int64, Boolean, Boolean, String, String, IDictionary`2) (at Library/PackageCache/com.unity.services.authentication@2.1.1/Runtime/Network/WebRequest.cs:192)
Unity.Services.Authentication.<>c__DisplayClass15_0:b__0(AsyncOperation) (at Library/PackageCache/com.unity.services.authentication@2.1.1/Runtime/Network/WebRequest.cs:75)
UnityEngine.AsyncOperation:InvokeCompletionEvent()

This is my Auth script, mostly just copy pasted from the docs:

async void Start()
{
MenuManager.instance.OpenMenu(“loading”);
// UnityServices.InitializeAsync() will initialize all services that are subscribed to Core.
await UnityServices.InitializeAsync();
Debug.Log(UnityServices.State);

SignInWithSteam();
}

Callback<GetAuthSessionTicketResponse_t> m_AuthTicketResponseCallback;
HAuthTicket m_AuthTicket;
string m_SessionTicket;

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_AuthTicketResponseCallback = Callback<GetAuthSessionTicketResponse_t>.Create(OnAuthCallback);

var buffer = new byte[1024];
m_AuthTicket = SteamUser.GetAuthSessionTicket(buffer, buffer.Length, out var ticketSize);

Array.Resize(ref buffer, (int)ticketSize);

// The ticket is not ready yet, wait for OnAuthCallback.
m_SessionTicket = BitConverter.ToString(buffer).Replace(“-”, string.Empty);
}

void OnAuthCallback(GetAuthSessionTicketResponse_t callback)
{
// Call Unity Authentication SDK to sign in or link with Steam.
Debug.Log("Steam Login success. Session Ticket: " + m_SessionTicket);
LogInToSteam(m_SessionTicket);
}

async void LogInToSteam(string ticket)
{
await SignInWithSteamAsync(ticket);
}

async Task SignInWithSteamAsync(string ticket)
{
try
{
await AuthenticationService.Instance.SignInWithSteamAsync(ticket);
Debug.Log(“SignIn is successful.”);
MenuManager.instance.OpenMenu(“lobby”);
}
catch (AuthenticationException ex)
{
// Compare error code to AuthenticationErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
catch (RequestFailedException ex)
{
// Compare error code to CommonErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
}

I got it working. I had to use the Web API key found in steamworks groups. I used the one I made here: Sign In <<< which doesn’t work

Hi @GlennVerheij

I’m glad to hear that you got it working,

Thanks for sharing your code snippet and the solution.

Where about did you insert your Web API key?

I’m sorry but how was this solved?
I’m using the exact same code from the examples like yours but I’m getting nowhere.
I’ve set up the Web API in the Unity Dashboard and it’s enabled.
I feel like I’m missing something really obvious.

[EDIT]
Yep. Need to use the Web API Key from the “Publisher Key” steps from this link https://partner.steamgames.com/doc/webapi_overview/auth.