Available in Classic and VPC
The following scenario describes how to set up authentication using a player's Steam account in a game.
- Set up login with Steam account
- Log in as an existing user or create a new user
- Update the user from anonymous login to platform login with a Steam account
To provide players with the option to log in to Steam, create an app in the Steamworks partner portal, log in users, and install the Steamworks.Net SDK to get session tickets.
Set up Steam account login
- Create an app and record the app ID following the Steamworks documentation. Steamworks documentation.
- Create a publisher web API key following the authentication using the web API key documentation. Authentication using Web API Keys
- Install the SteamWorks.Net SDK following the specific instructions for installing the SDK for Unity.
- Import the SteamWorks.Net SDK Unity plugin.
- Open steam_appid.txt in the root of the project and replace 480 with your app ID.
- Add the Steam Manager game component to the game object in the scene. This will initialize the Steam library.
- Before testing, make sure that Steam is installed and logged in, and that you are in the project library you are developing.
Steam login
- Download the latest version from Steamworks.NET and import it to Unity.

- After creating the steam_appid.txt file in the project root folder, enter the app ID issued by Steam and save it.

- Users & Permissions > Manage Group > Create Group > Create Web API Key.

- Add the Steam app ID and web API key to the GAMEPOT dashboard > Integration > Steam field.

Add SteamManager scene
Create an empty object in the hierarchy and add Assets > Scripts > Steamworks.NET > SteamManager.cs to it.

Add GAMEPOT login
After completing Steam login, process login for the Steam session ticket via signInWithCredential.
NBaseSDK.NBase.signInWithToken("steam", memberId, sessionTicket, (user, error) =>
{
try
{
if(error != null)
{
Debug.Log("Login Success - " + user.ToString());
}
memberId = user.Id;
}
catch (Exception ex)
{
Debug.Log($"An exception occurred during sign-in: {ex.Message}");
}
});
In-game code addition example
private Callback<GetAuthSessionTicketResponse_t> m_GetAuthSessionTicketResponse;
private byte[] m_Ticket;
private uint m_pcbTicket;
private HAuthTicket m_HAuthTicket;
// Run after NBase Initialize is complete.
private void Initialize()
{
try
{
InitializeSteamAuth();
// Check if Steam has been initialized
if (SteamManager.Initialized)
{
// Check Steam login status
if (SteamUser.BLoggedOn())
{
// If already logged in
CSteamID steamId = SteamUser.GetSteamID();
string steamName = SteamFriends.GetPersonaName();
Log($"Steam User Connected - Name: {steamName}, SteamID: {steamId}");
}
else
{
// If not logged in
Log("Steam user not logged in. Opening Steam login overlay.");
ShowBox("Steam must be running to play this game.");
}
}
else
{
Log("Steam is not initialized. Please make sure Steam is running.");
ShowBox("Steam must be running to play this game.\nPlease start Steam and restart the game.");
}
}
catch (Exception ex)
{
Log($"Failed to initialize Steam login: {ex.Message}");
ShowBox("Failed to connect to Steam. Please restart the game.");
}
}
private void OnDestroy()
{
CleanupAuthTicket();
}
private void InitializeSteamAuth()
{
if (!SteamManager.Initialized)
{
Log("Steam is not initialized. Skipping auth ticket generation.");
return;
}
try
{
// Create callback for auth ticket response
m_GetAuthSessionTicketResponse = Callback<GetAuthSessionTicketResponse_t>.Create(OnGetAuthSessionTicketResponse);
// Initialize ticket buffer
m_Ticket = new byte[1024];
// Create SteamNetworkingIdentity instance
SteamNetworkingIdentity networkingIdentity = new SteamNetworkingIdentity();
// Get auth session ticket with networking identity
m_HAuthTicket = SteamUser.GetAuthSessionTicket(
m_Ticket,
1024,
out m_pcbTicket,
ref networkingIdentity
);
if (m_HAuthTicket == HAuthTicket.Invalid)
{
throw new Exception("Failed to get valid Steam auth ticket");
}
Log($"Successfully generated Steam auth ticket. Ticket size: {m_pcbTicket} bytes");
}
catch (Exception ex)
{
Log($"Error during Steam auth ticket generation: {ex.Message}");
CleanupAuthTicket();
}
}
private void OnGetAuthSessionTicketResponse(GetAuthSessionTicketResponse_t pCallback)
{
try
{
if (pCallback.m_hAuthTicket != m_HAuthTicket)
{
Log("Received response for different auth ticket");
return;
}
// Resize to buffer of actual ticket size
System.Array.Resize(ref m_Ticket, (int)m_pcbTicket);
// Format as Hex
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (byte b in m_Ticket)
{
sb.AppendFormat("{0:x2}", b);
}
CSteamID steamId = SteamUser.GetSteamID();
sessionTicket = sb.ToString();
NBaseSDK.NBase.signInWithToken("steam", steamId.ToString(), sessionTicket, (user, error) =>
{
try
{
if(error != null)
{
Debug.Log("Login Success - " + user.ToString());
}
memberId = user.Id;
}
catch (Exception ex)
{
Debug.Log($"An exception occurred during sign-in: {ex.Message}");
}
});
switch (pCallback.m_eResult)
{
case EResult.k_EResultOK:
Log("Steam auth ticket successfully generated");
break;
case EResult.k_EResultInvalidParam:
Log("Steam auth ticket generation failed: Invalid parameters");
break;
case EResult.k_EResultLimitExceeded:
Log("Steam auth ticket generation failed: Limit exceeded");
break;
default:
Log($"Steam auth ticket generation failed: {pCallback.m_eResult}");
break;
}
}
catch (Exception ex)
{
Log($"Error processing auth ticket response: {ex.Message}");
}
}
private void CleanupAuthTicket()
{
if (m_HAuthTicket != HAuthTicket.Invalid)
{
try
{
SteamUser.CancelAuthTicket(m_HAuthTicket);
m_HAuthTicket = HAuthTicket.Invalid;
m_Ticket = null;
Log("Steam auth ticket cleaned up successfully");
}
catch (Exception ex)
{
Log($"Error cleaning up auth ticket: {ex.Message}");
}
}
}
Auto login processing example
This is an example of checking whether a user is logged in before performing automatic login processing.
NBaseSDK.NBase.signInLastLoggedIn((user, error) =>
{
if (error != null)
{
// If auto login does not work, process normal login
NBaseSDK.NBase.signInWithToken("steam", steamId.ToString(), sessionTicket, (user, error) =>
{
try
{
if(error != null)
{
Debug.Log("Login Success - " + user.ToString());
}
}
catch (Exception ex)
{
Debug.Log($"An exception occurred during sign-in: {ex.Message}");
}
});
}
else if(user != null)
{
// Auto login succeeded
Debug.Log("Login Success - " + user.ToString());
}
}