UGS Steam Authentication: [Authentication]: Request failed: 401, "detail":"invalid token"

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.

4 Likes

Hey casualtiesstudios,
I just checked the error in the logs for the request-id you posted and Steam is returning an error saying this ticket was generated for a different app, error code 102:
error code: 102
error description: “Ticket for other app”
Could you also print the AppId in the console for which you are requesting the ticket and send it here?

Just trying to understand how this can happen:
The session ticket gets generated through the Steamworks.NET API, which is using the AppId from the steam_appid.txt in the root folder.
The UGS Steam Authentication is using the AppId configured through project settings.
If those ID’s match, the Problem should never come up, right?

Would be really nice to have a single point of truth for the AppId to eliminate this type of error, but other than a patched Steamworks.NET I guess that’s not really possible?

The steamworks.NET API uses the AppId from the steam_appid.txt, provided the editor was loaded with that AppId already in place, it doesn’t pick up changes to the steam_appid.txt, so if you loaded the editor with a different AppId in the txt that could lead to this issue. That is why I wanted you to also log the appId for which the Steamworks.NET API is requesting the ticket, so we can be absolutely sure they are the same.
Also, what is the Authentication SDK version you’re using so we can try to reproduce in the exact same versions you are using?

That was it, thanks @davialbuquerque .
I changed the app id without restarting the editor, I just retried and I can login.
Cheers

Awesome!

I’m seeing this now, but with a Demo app id.

When I switch back to my main game app id, I’m able to successfully call SignInToSteamAsync. Once I change to the demo app id (and I’ve restarted Unity, just to be sure), I get the PERMISSION_DENIED error.

I’ve got the app printing out the app ID it thinks it has, and it’s definitely correct for the demo.

Any ideas?

[Authentication]: Request failed: 401, {“detail”:“invalid token”,“details”:,“status”:401,“title”:“PERMISSION_DENIED”}, request-id: ca0f6bcc-41c2-47df-9d39-8f2979b45562

NM, figured it out. Had to use the overload of SignInWithSteamAsync that accepts an AppId.

Thanks!

3 Likes

Using the overload with AppId also fixed my issue. Thanks, @dariakus!

In my case, it always worked without passing the AppId because I was testing only the Demo app and had only this Demo AppId set in the Steam Provider at UGS.

But when I started using the “Additional App IDs for my FullGame, Demo and Playtest” feature in the Steam Provider, to add the FullAppId, I started getting the error:
[Authentication]: Request completed with error: {"detail":"invalid token","details":[],"status":401,"title":"PERMISSION_DENIED"}

Then I had to use the “SignInWithSteamAsync” and “LinkWithSteamAsync” overloads with the correct AppId, despite having the steam_appid.txt in the project. Thas is annoying… :frowning:

hey @davialbuquerque, do you know if that is expected by design?

Yo, it’s 2025, this topic is solved. But I had to give a shoutout to this man, I’ve been toiling for WEEKS! with a problem while authenticating with steam. It worked with my demo AppId, but it was failing on other environments, like playtest or prod. I added the Steam appId, it works like a damn charm now. Thanks sir!