Search Unity

Question SignInWithSteamAsync Invaild Token Error

Discussion in 'Authentication' started by Ed-Gilmour, May 6, 2023.

  1. Ed-Gilmour

    Ed-Gilmour

    Joined:
    Dec 14, 2021
    Posts:
    14
    Hello,

    I've got a Steam page for my game and I've put in the web API and AppID in the project settings, and the AppID in the steam AppID text file (and yes I've quadruple checked) but when I use the code I got from the documentation I get an invalid token error. I have a SteamManager in my scene which I got from Steamworks.net that calls the Steam Init function. I've been stuck on this for several days and none of the solutions I've found online have worked. It doesn't work in the editor play mode or in the build and I'm using Steamworks.net for my Steam integration. Also I've just got this script on an empty game object in my menu scene. I'm also a little confused about beginning and ending an auth session and I've struggled to find much about that online. Any help is very much appreciated, thank you!

    Here is my code:

    Code (CSharp):
    1. using Steamworks;
    2. using System;
    3. using UnityEngine;
    4. using Unity.Services.Authentication;
    5. using Unity.Services.Core;
    6.  
    7. public class SteamAuth : MonoBehaviour
    8. {
    9.     Callback<GetAuthSessionTicketResponse_t> m_AuthTicketResponseCallback;
    10.     HAuthTicket m_AuthTicket;
    11.     string m_SessionTicket;
    12.  
    13.     void Awake()
    14.     {
    15.         SignInWithSteam();
    16.     }
    17.  
    18.     void SignInWithSteam()
    19.     {
    20.         // It's not necessary to add event handlers if they are
    21.         // already hooked up.
    22.         // Callback.Create return value must be assigned to a
    23.         // member variable to prevent the GC from cleaning it up.
    24.         // Create the callback to receive events when the session ticket
    25.         // is ready to use in the web API.
    26.         // See GetAuthSessionTicket document for details.
    27.         m_AuthTicketResponseCallback = Callback<GetAuthSessionTicketResponse_t>.Create(OnAuthCallback);
    28.  
    29.         var buffer = new byte[1024];
    30.         m_AuthTicket = SteamUser.GetAuthSessionTicket(buffer, buffer.Length, out var ticketSize);
    31.  
    32.         Array.Resize(ref buffer, (int)ticketSize);
    33.  
    34.         // The ticket is not ready yet, wait for OnAuthCallback.
    35.         m_SessionTicket = BitConverter.ToString(buffer).Replace("-", string.Empty);
    36.     }
    37.  
    38.     async void OnAuthCallback(GetAuthSessionTicketResponse_t callback)
    39.     {
    40.         // Call Unity Authentication SDK to sign in or link with Steam.
    41.         await UnityServices.InitializeAsync();
    42.         await AuthenticationService.Instance.SignInWithSteamAsync(m_SessionTicket);
    43.         Debug.Log("Steam Login success. Session Ticket: " + m_SessionTicket);
    44.     }
    45. }
    I'm getting these errors:

    WebRequestException: {"title":"PERMISSION_DENIED","detail":"invalid token","details":[],"status":401}

    [Authentication]: Request completed with error: {"title":"PERMISSION_DENIED","detail":"invalid token","details":[],"status":401}

    [Authentication]: Request failed: 401, {"title":"PERMISSION_DENIED","detail":"invalid token","details":[],"status":401}
     
  2. Ed-Gilmour

    Ed-Gilmour

    Joined:
    Dec 14, 2021
    Posts:
    14
    I'm currently working on adding multiplayer and it would be very useful to get this working soon, thanks! :D
     
  3. Ed-Gilmour

    Ed-Gilmour

    Joined:
    Dec 14, 2021
    Posts:
    14
    I finally got it working!!!!! :D
     
    SebT_Unity likes this.
  4. SebT_Unity

    SebT_Unity

    Unity Technologies

    Joined:
    Jun 21, 2021
    Posts:
    282
    Hi Ed-Gilmour,

    Could you share with us how you got this to work!?
    Look forward to your response!
     
  5. Ed-Gilmour

    Ed-Gilmour

    Joined:
    Dec 14, 2021
    Posts:
    14
    I would have shared my solution but it was just a stupid mistake from me. I forgot to install the Steamworks SDK into my project :(
     
    SebT_Unity likes this.
  6. SebT_Unity

    SebT_Unity

    Unity Technologies

    Joined:
    Jun 21, 2021
    Posts:
    282
    Hey Ed-Gilmour,

    There is only learning from mistakes!
    Thanks for sharing this may help someone else!