Authenticate with Steam #
In this section, we will log into the platform with Steam. This method is appropriate for use in production. A Steam account associated with a Steamworks organization is required to complete this section.
We will use the PragmaManager.cs
class we created in Create Unity Project Files to add a Steam login method, as well as Unity editor elements created in Log in from a Game Client.
Prerequisites:
- A Steam account associated with a Steamworks organization
- Set Up Unity Project
- Set Up the Unity SDK
- Create Unity Project Files
- Handle login and logout with Unity
Acquire the Steam Application ID and Steamworks Web API key #
This guide assumes that you have already created and published your game on Steam. Consult Valve’s official Steam documentation for further assistance.
- Log into Steamworks.
- Hover over Users & Permissions, then click Manage Groups.
- Select a group or create a new group.
- Create or view your Steamworks Web API Key.
- Take note of your game’s Steam Application ID. Hover over Users & Permissions, then click View Applications. The number that appears in the App Name column beneath the game name is the Steam Application ID.
Configure the Pragma Engine Steam Identity Provider #
Navigate to the
pragma-engine/platform/PROJECT/config/
directory and openlocal-dev.yml
.Insert the following code while making sure to edit in your Application ID and Web API Key:
Be sure to nest the configuration under AccountService.identityProviderPlugins
if you already have other identity providers configured.
social:
pluginConfigs:
AccountService.identityProviderPlugins:
plugins:
Steam:
class: "pragma.account.SteamIdentityProviderPlugin"
config:
appId: "${steamAppId}"
steamWebAPIKey: "${steamWebApiKey}"
restrictByAppOwnership: false
restrictByAccountBan: false
playerLoginEnabled: true
operatorLoginEnabled: false
accountLinkingEnabled: true
showPortalLoginButton: false
visibleToOtherPlayers: true
- Run Pragma Engine via one of the following methods.
Once the engine has started successfully, it prints the message INFO main - Pragma server startup complete
.
Import Steamworks.NET into Unity #
Follow the Steamworks.NET installation instructions on the Steamworks.NET website, including creating the
SteamManager
MonoBehavior class in yor Assets/Scripts folder.We recommend using Option B or Option C. We do not recommend Option A as Steamworks.NET has not provided an up-to-date prepackaged build in some time.
In the
steam_appid.txt
file that now resides in the root of your Unity project, replace 480 with your Steam Application ID.
Integrate Steam login into your game #
- In
PragmaManager.cs
, add the following imports:
using Steamworks;
using System.Text;
- Add a
GetSteamToken()
andLogInViaSteam()
method:
public string GetSteamToken()
{
SteamNetworkingIdentity identity = new SteamNetworkingIdentity();
byte[] ticketBlob = new byte[1024];
SteamUser.GetAuthSessionTicket(ticketBlob, ticketBlob.Length, out var ticketSize, ref identity);
// Convert the ticketBlob to a hex string
StringBuilder steamTicketBuilder = new StringBuilder();
for (int i = 0; i < ticketSize; i++)
{
steamTicketBuilder.AppendFormat("{0:x2}", ticketBlob[i]);
}
return steamTicketBuilder.ToString();
}
public void LoginViaSteam()
{
Player.LogIn(Pragma.Account.IdProvider.Steam, GetSteamToken(), HandleLoggedIn);
}
In your Unity Editor, create a Steam Login UI button for logging in via Steam. Drag the
SteamManager
script onto your login button.Connect your Steam login button to the Pragma Manager
GetSteamToken ()
method when clicked.Ensure that you have Steam running and that you’re logged in.
In Unity Editor, click the play button, then click your Steam Login button.
Navigate to your local Pragma Portal then sign in via Pragma Unsafe using the
test04
account.Confirm you see both the
test04
account and your Steam account’s display name in the list of logged-in players.Click on the Steam account’s display name. Under the Identity providers section, verify that the account’s identity provider is Steam.