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.
Complete Set Up the Unity SDK and Log into the Platform before starting this section.
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/5-ext/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 [main] INFO main - Pragma server startup complete
.
Import Steamworks.NET into Unity #
- Install the Steamworks.NET
unitypackage
. We recommend using Option B from the project’s installation page. Alternatively, you can use Option C. We do not recommend Option A as Steamworks.NET has not provided an up-to-date prepackaged build in some time. - Open your game project in Unity Editor. Follow the Option B directions to install the Steamworks.NET package.
- Locate the
steam_appid.txt
file in the root directory of your Unity project. Replace the contents of this file with your Steam Application ID.
Integrate your game with Steam #
- Open
PragmaManager.cs
, and insert the following imports:
using Steamworks;
using System.Text;
- Add the following methods to the
PragmaManager
class:
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 Unity Editor, locate the
SteamManager
script in the Project panel underAssets/Scripts/Steamworks.NET
. Drag theSteamManager
script onto the Login button.
Select the
Login
button in the Hierarchy panel. In the Inspector panel, change the On Click () function toPragmaManager.GetSteamToken ()
.Ensure that you have Steam running and that you’re logged in.
In Unity Editor, click the play button, then click the 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.