Skip to main content

Relogin using cached refresh token

Last updated on December 21, 2023

Overview

The AccelByte Gaming Services (AGS) Game SDK allows game developers to implement the relogin feature so that users in a game can remain logged in using a cached refresh token. This capability is useful to authenticate a player when a third-party service is down. We currently support this in the Windows platform for Steam, which allows a user to stay logged in and authenticated when the Steam service is down or under maintenance. The user can be logged in using the refresh token for the next 24 hours (one day).

Implementation

The Game SDK logs the player in successfully first using the LoginWithOtherPlatform function from the AccelByte User API. If the login succeeds, then the refresh token will be generated and cached automatically. The caching does not need an explicit call. After that point, the ReloginWithOtherPlatform function can be used when the platform service is down or unavailable, and the relogin API will use the last generated platform refresh_token to log in to the AccelByte platform.

Examples of the same can be seen below.

//Try to login using Steam first
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString SteamTicket = GetSteamTicket(); // using UnrealEngine Online Subsystem Steam
bool bLoginDone = false;
bool bLoginUsingSteamAccountSuccess = false;
ApiClient->User.LoginWithOtherPlatform(EAccelBytePlatformType::Steam, SteamTicket,
FVoidHandler::CreateLambda([&]()
{
bLoginDone = true;
bLoginUsingSteamAccountSuccess = true;
}),
FErrorHandler::CreateLambda([&](int32 Code, FString Message)
{
bLoginDone = true;
}));

WaitUntil([&]() { return bLoginDone; }, "Waiting...");

FString SteamID = GetSteamUserId(); // using Steamworks

/// EXAMPLE:
/// FString GetSteamUserId()
/// {
/// SteamID SteamID = SteamUser()->GetSteamID();
/// uint64 SteamIdLong = SteamID.ConvertToUint64();
/// return FString::Printf(TEXT("%llu"), SteamIdLong);
/// }

if (bLoginUsingSteamAccountSuccess)
{
return;
}

// When login using Steam account failed due to any reason (i.e. Steam API is down)
// Use this example to relogin using cached refresh token
bool bReloginDone = false;
bool bReloginSuccess = false;
ApiClient->User.TryRelogin(SteamID,
FVoidHandler::CreateLambda([&]()
{
bReloginDone = true;
bReloginSuccess = true;
}),
FErrorHandler::CreateLambda([&](int32 Code, FString Message)
{
bReloginDone = true;
}));
WaitUntil([&]() { return bReloginDone; }, "Waiting...");