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/5-ext/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 Make
Run make run to start the platform. Run this in a terminal with platform as the working directory.
Running in IntelliJ

From the IntelliJ toolbar in the upper right, ensure 5-ext - LocalConfigured is selected, then click the play button.

If 5-ext - LocalConfigured isn’t available, you will need to configure it. In the IntelliJ toolbar, click the dropdown next to the run button, then click Edit Configurations…. In the Run/Debug Configurations window that appears, expand Kotlin in the left hand side, then select 5-ext - LocalConfigured. Click OK. Click the play button in the IntelliJ toolbar to start Pragma Engine.

Once the engine has started successfully, it prints the message [main] 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 void GetSteamToken()
{
    string steamTicket;
    byte[] ticketBlob = new byte[1024];
    uint ticketSize;
    HAuthTicket ticket = SteamUser.GetAuthSessionTicket(ticketBlob, ticketBlob.Length, out ticketSize);

    StringBuilder sb = new StringBuilder();
    foreach (byte b in ticketBlob)
    {
        sb.AppendFormat("{0:x2}", b);
    }

    steamTicket = sb.ToString();
    LoginViaSteam(steamTicket);
}

public void LoginViaSteam(string steamToken)
{
    player.LogIn(IdProvider.Steam, steamToken, 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.