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.
  1. Log into Steamworks.
  2. Hover over Users & Permissions, then click Manage Groups.

  1. Select a group or create a new group.

  1. Create or view your Steamworks Web API Key.
Create a key

If a key doesn’t yet exist, you must create one by clicking Create WebAPI Key. It will then appear.

View an existing key

If you selected an existing group which already has a Web API key, you’ll see it listed under the Web API box on the right-hand side.

  1. 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 #

  1. Navigate to the pragma-engine/platform/<PROJECT>/config/ directory and open local-dev.yml.

  2. 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
  1. Run Pragma Engine via one of the following methods.
Running via Command Line
From your pragma-engine/platform working directory, run ./pragma run to start the platform.
Running in IntelliJ
Run Pragma from the IDE by selecting the ‘Run Pragma’ run configuration from the dropdown in the upper right.

Once the engine has started successfully, it prints the message INFO main - Pragma server startup complete.

Import Steamworks.NET into Unity #

  1. 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.
  2. Open your game project in Unity Editor. Follow the Option B directions to install the Steamworks.NET package.
  3. 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 #

  1. Open PragmaManager.cs, and insert the following imports:
using Steamworks;
using System.Text;
  1. 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);
}
  1. In Unity Editor, locate the SteamManager script in the Project panel under Assets/Scripts/Steamworks.NET. Drag the SteamManager script onto the Login button.

  1. Select the Login button in the Hierarchy panel. In the Inspector panel, change the On Click () function to PragmaManager.GetSteamToken ().

  2. Ensure that you have Steam running and that you’re logged in.

  3. In Unity Editor, click the play button, then click the Login button.

  4. Navigate to your local Pragma Portal then sign in via Pragma Unsafe using the test04 account.

  5. Confirm you see both the test04 account and your Steam account’s display name in the list of logged-in players.

  6. Click on the Steam account’s display name. Under the Identity providers section, verify that the account’s identity provider is Steam.