Authenticating 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 Setting Up the Unity SDK and Logging 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 Platform Steam Identity Provider #

  1. Navigate to the pragma-engine/platform/5-ext/config directory and open LocalConfig.yml.

  2. Insert the following code while making sure to edit in your Application ID and Web API Key:

Be sure to nest AccountService.steamIdentityProvider under pluginConfigs if you already have other identity providers configured.
social:
  pluginConfigs:
    AccountService.steamIdentityProvider:
      class: "pragma.account.SteamIdentityProvider"
      config:
        appId: "YOUR STEAM APPLICATION ID HERE"
        steamWebAPIKey: "YOUR STEAM WEB API KEY HERE"
  1. Run make run to start Pragma Engine. Run this in a terminal with platform as the working directory.
  • Alternatively, Pragma Engine can be run from IntelliJ. From the IntelliJ toolbar in the upper right, ensure MainKt - LocalConfigured is selected, then click the play button.

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

Import Steamworks.NET into Unity #

  1. Download the Steamworks.NET unitypackage. You can find this by click on the Option A link on the project’s installation page.
  2. Open your game project in Unity Editor. Double click the downloaded unitypackage from your File Explorer to import it.
  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)
{
    session.Account.LogIn(IdProvider.Steam, steamToken, loginResult =>
    {
        if (loginResult.IsSuccessful)
        {
            // Success is handled in_session.Connection.OnInitiallyConnected above.
            // No reason you couldn't handle it here though.

            return;
        }
        else
        {
            //Something went wrong
        }
    });
}
  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 Platform’s 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.