Authentication with Steam #

In this section, we’ll log into the platform with Steam. This method is appropriate for use in production.

Prerequisites:

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
steamWebAPIKey does not need to be encrypted when running Pragma Engine locally.
  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.

Enable Unreal’s Steam plugin #

You will need to replace your_app_id with your app’s Steam App ID.
  1. Open DefaultEngine.ini located in the Unreal Projects/[Project name]/Config directory and add the following configs:
[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")

[OnlineSubsystem]
DefaultPlatformService=Steam

[OnlineSubsystemSteam]
bEnabled=true
SteamDevAppId=your_app_id

[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"

[PacketHandlerComponents]
+Components=OnlineSubsystemSteam.SteamAuthComponentModuleInterface
  1. Open [Project Name].Build.cs and add "OnlineSubsystem", "OnlineSubsystemSteam", "Steamworks" to PublicDependencyModuleNames.AddRange. Confirm that your PublicDependencyModuleNames.AddRange follows this structure:
PublicDependencyModuleNames.AddRange(
    new string[] {
        "Core",
        "CoreUObject",
        "Engine",
        "InputCore",
        "PragmaSDK",
        "PragmaSDKAux",
        "OnlineSubsystem",
        "OnlineSubsystemSteam",
        "Steamworks"
    }
);
  1. Open your project in Unreal Editor.
  2. Click on the Edit menu, then Plugins to open the Plugins window.
  3. Ensure that both the Online Subsystem and Online Subsystem Steam plugins are enabled, then restart Unreal Editor.

Integrate Steam login into your game #

We will use the PC_TutorialPlayerController class we created in Log Into the Platform to add a Steam login method.

  1. Open PC_TutorialPlayerController.h and insert the following under the public access modifier:
UFUNCTION(Exec)
void LogInSteam();
void GetSteamToken();
  1. Open PC_TutorialPlayerController.cpp and add the following includes:
#include "Online.h"
#include "OnlineSubsystem.h"
  1. Add the following methods:
FString APC_TutorialPlayerController::GetSteamToken()
{
  IOnlineSubsystem* OSS = IOnlineSubsystem::Get();
  return OSS->GetIdentityInterface()->GetAuthToken(0);
}

void APC_TutorialPlayerController::LogInSteam()
{
  Player->LogIn(EPragma_Account_IdProvider::STEAM, GetSteamToken(), Pragma::FPlayer::FLoggedInDelegate::AddUObject(this, &APC_TutorialPlayerController::HandleLoggedIn));
}
  1. Compile the project in your IDE.

Build a standalone binary #

The Steam Online Subsystem in Unreal Engine does not work in PIE (Play In Editor) mode. It will still work if you run using the “Standalone Game” option.
In the Edit menu under Project Settings…, ensure that your project’s Default GameMode is set to TutorialGameMode before packaging a standalone version of your project.
  1. Build a standalone version of your game by going to the File menu, Package Project, then building a Windows (64-bit) version of the game.

  1. Ensure Pragma is running. Confirm that your Steam client is open and logged in with the same account used to get the Steam App ID.

  2. Navigate to the location of the built project. You should find [Your project name].exe inside the WindowsNoEditor directory.

  3. Create a shortcut to [Your project name].exe, then right-click the shortcut left-click Properties.

  4. In the Shortcut Properties window, add a space and -log to the end of the Target field. The Target field should read path to your executable\[Your project name].exe -log. You will now see a separate log window appear when launching your standalone game via this shortcut.

  5. Open your standalone game using the shortcut you just created.

  6. Run the game, open the in-game console with ~, and type LogInSteam.

  7. If successful, you should see the app you registered with Steam running inside the Steam client. A separate log window should open and you should see a successful login attempt via Steam.

For extra confirmation, you can use the Pragma Portal to verify a successful Steam login.
  1. Navigate to http://localhost:10200/ to load Pragma Portal. Select Sign in with Pragma Unsafe and type in test04.

  2. Confirm you see a player with your Steam display name listed in the Players section of the portal. Clicking on this player should show that the identity provider for this player is Steam.