Login #

The player login flow is initiated via the Pragma SDK, expecting an identity provider id and token. The Pragma Account service will validate the identity provider token and produce Pragma session tokens. Typically a game and social token will be returned, which enables the SDK to establish a session with both game and social backend shards.

Additional login options are available to specify additional information about a client, such as the distribution platform or hardware class the client is running on.

Unreal SDK #

For a full walkthrough, see the Set up the Unreal SDK tutorial.

Basic Login:

Source\Unicorn\UnicornPlayerController.cpp

#include "UnicornPlayerController.h"
#include "PragmaPlayer.h"
#include "PragmaLocalPlayerSubsystem.h"

void AUnicornPlayerController::BeginPlay()
{
    Super::BeginPlay();

    const auto* Pragma = GetLocalPlayer()->GetSubsystem<UPragmaLocalPlayerSubsystem>();
    Player = Pragma->Player();

    // Log in using a built-in test account.
    // Accounts test01 - test20 are available by default.
    LogIn("test01");
}

void AUnicornPlayerController::LogIn(const FString& Username)
{
    Player->LogIn(
        EPragma_Account_IdProvider::UNSAFE,
        Username,
        Pragma::FPlayer::FLoggedInDelegate::CreateWeakLambda(
            this, [this, Username = Username](const TPragmaResult<>& Result)
            {
                if (Result.IsSuccessful())
                {
                    UE_LOG(LogTemp, Display, TEXT("Pragma -- Logged in as user %s."),
                        *Username);
                }
                else
                {
                    UE_LOG(LogTemp, Error, TEXT("Pragma -- Login failed: %s"),
                        *Result.GetErrorAsString());
                }
            }));
}

void AUnicornPlayerController::LogOut()
{
    Player->LogOut(
        Pragma::FPlayer::FLoggedOutDelegate::CreateWeakLambda(
            this, []
            {
                UE_LOG(LogTemp, Display, TEXT("Pragma -- Logged out."));
            }));
}

Login using FPragmaLoginOptions to include platform and hardware metadata:

FPragmaLoginOptions LoginOptions;
LoginOptions.DistributionPlatform = TEXT("STEAM");
LoginOptions.HardwareClass = TEXT("PC");
LoginOptions.HardwareDevice = TEXT("alienware");

PragmaPlayer->LogIn(
    EPragma_Account_IdProvider::STEAM,
    ProviderToken,
    LoginOptions,
    Pragma::FPlayer::FLoggedInDelegate::CreateWeakLambda(this,
        [](const TPragmaResult<>& Result)
        {
            if (Result.IsSuccessful())
            {
                // classifiers are now stored in the session JWT
            }
        }
    )
);

Unity SDK #

For a full walkthrough, see the Set up the Unity SDK tutorial.

Basic login:

Scripts\PragmaManager.cs

using UnityEngine;

public class PragmaManager : MonoBehaviour
{
    public Pragma.Player Player { get; private set; }

    private void Awake()
    {
        // The Pragma Runtime is automatically initialized on first retrieval.
        var runtime = Pragma.Runtime.Get();

        // This returns the first Player if available, or creates it. The Runtime is the source of truth for Player objects.
        Player = runtime.Player();
    }

    public void LogIn()
    {
        Player.LogIn(Pragma.Account.IdProvider.Unsafe, "test01", HandleLoggedIn);
    }

    public void LogOut()
    {
        Player.LogOut(HandleLoggedOut);
    }

    private void HandleLoggedIn(Pragma.Result<string> result)
    {
        if (result.IsFailure)
        {
            Debug.LogErrorFormat("Pragma -- Login failed: {0}", result.ErrorCode);
            return;
        }
        Debug.Log("Pragma -- Logged in.");
    }

    private void HandleLoggedOut()
    {
        Debug.Log("Pragma -- Logged out.");
    }    
}

Login using LoginOptions to include platform and hardware metadata:

var loginOptions = new LoginOptions
{
    DistributionPlatform = "STEAM",
    HardwareClass = "PC",
    HardwareDevice = "alienware"
};

_player.LogIn(IdProvider.Steam, providerToken, loginOptions, result =>
{
    if (result.IsSuccessful)
    {
        // classifiers are now stored in the session JWT
    }
});

Login Options #

Login Options are optional fields you can send to describe the player’s environment. The values below are conventions, but you may pass any string your studio requires. Being consistent with these values will make it easier to leverage in various use cases such as telemetry events or cross-play matchmaking logic.

FieldDescriptionExample values
DistributionPlatformWhere the player purchased or obtained the gameSTEAM, EPIC, XBOX, PLAYSTATION, NINTENDO
HardwareClassCategory of device the game is running onPC, MOBILE, CONSOLE
HardwareDeviceSpecific physical devicerazer-blade-14, iPhone17, Xbox Series X

Once provided, the classifiers are stored in the player’s session JWT and are available to backend services for the duration of the session.

Login queue #

To prevent your game from crashing during peak hours the login queue routes your players through a queue when they attempt to log in using your authentication services. With the login queue:

  • You can rate limit logins to help manage larger than normal requests to your game, such as on launch days
  • You can use authentication servers with lower hardware requirements without the risk of server overload
  • You can provide more information to your players on the login screen
See the Get Started with Login Queues guide for more details.