Authentication with Steam #
In this section, we’ll log into the platform with Steam. This method is appropriate for use in production.
Prerequisites:
- A Steam account associated with a Steamworks organization
- Set Up the Unreal SDK
- Create Player Controller and Blueprint
- Handle login and logout
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
steamWebAPIKey
does not need to be encrypted when running Pragma Engine locally.
- 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
.
Enable Unreal’s Steam plugin #
You will need to replace your_app_id
with your app’s Steam App ID.
- Open
DefaultEngine.ini
located in theUnreal 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
- Open
[Project Name].Build.cs
and add"OnlineSubsystem", "OnlineSubsystemSteam", "Steamworks"
toPublicDependencyModuleNames.AddRange
. Confirm that yourPublicDependencyModuleNames.AddRange
follows this structure:
PublicDependencyModuleNames.AddRange(
new string[] {
"Core",
"CoreUObject",
"Engine",
"InputCore",
"PragmaSDK",
"PragmaSDKAux",
"OnlineSubsystem",
"OnlineSubsystemSteam",
"Steamworks"
}
);
- Open your project in Unreal Editor.
- Click on the Edit menu, then Plugins to open the Plugins window.
- 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.
- Open
PC_TutorialPlayerController.h
and insert the following under thepublic
access modifier:
UFUNCTION(Exec)
void LogInSteam();
void GetSteamToken();
- Open
PC_TutorialPlayerController.cpp
and add the following includes:
#include "Online.h"
#include "OnlineSubsystem.h"
- 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));
}
- 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 GM_TutorialGameMode
before packaging a standalone version of your project.
- 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.
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.
Navigate to the location of the built project. You should find
[Your project name].exe
inside theWindowsNoEditor
directory.Create a shortcut to
[Your project name].exe
, then right-click the shortcut left-click Properties.In the Shortcut Properties window, add a space and
-log
to the end of the Target field. The Target field should readpath 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.Open your standalone game using the shortcut you just created.
Run the game, open the in-game console with
~
, and typeLogInSteam
.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.
Navigate to http://localhost:10200/ to load Pragma Portal. Select Sign in with Pragma Unsafe and type in test04.
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.