Tutorial - Authentication with Steam

Information in this guide is correct from date of upload: 2024/10/21

A step by step authentication tutorial made to facilitate getting started with Steam and Unity Authentication.

Requirements

** We assume that you have a Steam account or Steam Developer account. If not please follow the existing steam guide

Steam Configuration

This section will go over the general setup within SteamWorks.

SteamWorks

The following information assists in retrieving and setting up the Publisher Web API Key and the App ID.

  1. Log in to the SteamWorks dashboard with a user who has administrative rights.

  2. On the Main SteamWorks page select Users & Permissions > Manage Groups.

  3. Select the Group to be modified; by default, Everyone should be visible.

  4. Create a WebAPI key on the right hand side of the page under edit group:

  5. Copy the Web API key, as it will be necessary when setting up the Unity project.

  6. Copy the App ID:

  7. Go to SteamWorks dashboard > Apps & Packages > All Applications.

  8. Select the newly created application.

  9. The App ID can be found in the URL and in brackets next to the app name.

With all the necessary information gathered, the setup can continue within the Unity Editor.

Unity Configuration

This section will go over the general setup within the Unity Editor.

SDK Configuration

  1. Create or Open a new Unity Project.
  2. Download the latest version of the SteamWorks SDK.
  3. In Unity, go to Assets > Import Package > Custom Package and select the SteamWorks .unitypackage file to import.
  4. Install the Unity Authentication SDK with package manager.
  • In Unity, go to Windows > Package Manager > Packages: (dropdown menu) > Unity Registry, and search Authentication in search bar.
  1. Once the installation is complete, a file named steam_appid.txt should appear in the root of the project.
  2. Update the application ID in the file with the previously obtained Steam App ID
  • No spaces or special characters allowed.

SteamManager Object

  1. Right click in the Unity Editor hierarchy and select Create > Empty GameObject.
  2. Rename to SteamManager.
  3. Select the SteamManager game object and select Add Component.
  4. Search for SteamManager.cs from the list and add it to the newly created SteamManager game object.

SteamAuthentication Object

  1. Right click in the Unity editor hierarchy and select Create > Empty GameObject.
  2. Rename to SteamAuthentication.
  3. Select the SteamAuthentication game object and select Add Component.
  4. Scroll down and click New script.
  5. Name script SteamAuthentication.
  6. Copy the following script directly into the newly created SteamAuthentication script.
  7. Make sure to change identity (ugsIdentity) to something unique with lowercase characters:
using Unity.Services.Authentication;
using System.Threading.Tasks;
using UnityEngine;
using System;
using Steamworks;
using Unity.Services.Core;




public class SteamAuthentication : MonoBehaviour
{
    //Variables
    Callback<GetTicketForWebApiResponse_t> m_AuthTicketForWebApiResponseCallback;
    HAuthTicket m_AuthTicket;
    string m_SessionTicket;


    //an identity that you create unique to the application
    private const string ugsIdentity = "unity";


    async void Start()
    {
        await UnityServices.InitializeAsync(); //Initialize UnityServices
        SignInWithSteam();
    }
   
    public void SignInWithSteam()
    {
        m_AuthTicketForWebApiResponseCallback =
            Callback<GetTicketForWebApiResponse_t>.Create(OnAuthCallback);
        m_AuthTicket = SteamUser.GetAuthTicketForWebApi(ugsIdentity);
    }


    async void OnAuthCallback(GetTicketForWebApiResponse_t callback)
    {
        // Call Unity Authentication SDK to sign in or link with Steam.
        // Retrieve the SteamID from SteamNetworkingIdentity.


        m_SessionTicket =
            BitConverter.ToString(callback.m_rgubTicket).Replace("-", string.Empty);
        m_AuthTicketForWebApiResponseCallback.Dispose();
        m_AuthTicketForWebApiResponseCallback = null;
        Debug.Log($"Steam Login success. Session Token: {m_SessionTicket} | Identity {ugsIdentity}");
        await SignInWithSteamAsync(m_SessionTicket, ugsIdentity);
    }


    async Task SignInWithSteamAsync(string ticket, string identity)
    {
        try
        {
            await AuthenticationService.Instance.SignInWithSteamAsync(ticket, identity);
            var playerInfo =
                await AuthenticationService.Instance.GetPlayerInfoAsync();
            string steamUserID = playerInfo.GetSteamId(); //Steam ID
            string steamName = SteamFriends.GetPersonaName(); //SteamName
            Debug.Log($"SteamID:{steamUserID} - Steam Name: {steamName}");


            //Unity PlayerName
            string playerName =
                await AuthenticationService.Instance.GetPlayerNameAsync();
            Debug.Log($"SignIn is successful: {playerName}");
        }
        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);
        }
    }


}

Unity Authentication Configuration

Almost at the finish line! A few more configuration steps and the application can be tested.

  1. Head to Edit > Project Settings > Services > Authentication.
  2. From the drop down list add Steam as an identity provider.
  3. Enter the Steam App ID that was copied earlier
  4. Enter the Steam Web API Key that was copied earlier

Testing

Following the above steps allows testing directly in the editor. Ensure that Steam is open; otherwise, an initialization failure error will occur.

The console should be logging the following if all is working as expected:

Common Errors

Initialisation failed If your initialization of SteamWorks fails, this indicates one of the following conditions:

  • The Steam client isn’t running. A running Steam client is required to provide implementations of the various Steamworks interfaces.
  • The Steam client couldn’t determine the App ID of the application. If you’re running your application from the executable or debugger directly then you must have a [code-inline]steam_appid.txt[/code-inline] in your game directory next to the executable, with your app ID in it and nothing else. Steam will look for this file in the current working directory. If you are running your executable from a different directory you may need to relocate the [code-inline]steam_appid.txt[/code-inline] file.
  • Your application is not running under the same OS user context as the Steam client, such as a different user or administration access level.
  • Ensure that you own a license for the App ID on the currently active Steam account. Your game must show up in your Steam library.
  • Your App ID is not completely set up, i.e. in Release State: Unavailable, or it’s missing default packages.

Invalid Parameters The identity may be too long; keep it between 5 and 8 characters. Make sure the identity is in lowercase

Editor works, Build does not Ensure the steam_appid.txt is placed in the root of the build folder.

Permission Denied A Web API specific to the application may not have been created yet. Follow the steps above under SteamWorks WebAPI to set it up.

Friends not seeing me using/playing my app The application must be published and live for it to be visible to other Steam users.

Conclusion

This covers the basics of Steam and Unity sign-in. For further details, refer to the Unity Authentication documentation or visit Unity Discussions for assistance.

16 Likes

Thanks for this guide!
Is there any way main Steam tutorial doc can get updated with some or all of this example? It really helped show the order in which things should be called.

1 Like

I’m happy this helped, @rxr_russ. I will follow up with the docs team, as when this was released, we had talked about adding this tutorial to the main documentation.

1 Like

Awesome post. Clear, concise. Thanks a lot for taking the time to set it up <3
Still works on 03/10/2025 using unity 6000.0.37

1 Like

Does this solution allow the developer to debug multiple clients open locally at the same time? How would that work? Since there is just one steam account per pc.

1 Like

That’s a great question. The quick answer is no; this would be testing one local Steam account.
Can you give me a scenario where this would be useful? Testing a multiplayer game locally with multiple Steam accounts?

Does your current computer allow you to log in to multiple Steam accounts?