Skip to main content

Authenticating With the SDK

The FACEIT SDK Authentication interface enables an external identity provider to integrate with and use the FACEIT ecosystem. The interface provides authentication services both for the FACEIT Server and Client SDKs.

Note that before authentication can be attempted, the SDK must first be initialised.

Client SDK Configuration

Authentication

The FACEIT Client SDK's Authentication interface provides access to FACEIT's game services for a game client. A player can associate one or more external user accounts, such as a Steam account they use for a particular game, with their FACEIT user account.

To use the SDK, the current player must be authenticated with FACEIT. This is performed by calling the FGCSDK_Auth_Login() function on the Auth interface. No FACEIT Client SDK interfaces will operate before a successful authentication call through this interface.

Steam is commonly used as a third-party user authentication platform, as demonstrated in the example below. See the Steamworks documentation for more information on how to obtain an authentication token for a Steam user.

#include "FACEITGameClientSDK/Auth/Auth.h"

FGCSDK_Auth_LoginCredentials credentials {};

// The auth platform is a supported authentication platform that the current
// player is logged into, eg. "steam".
credentials.authPlatform = "steam";

// The game ID is the ID of your game on FACEIT Game Studio or Labs Portal.
credentials.gameID = "...";

// The user auth token is a token obtained for the user for this auth platform,
// which proves their authenticity. For Steam, this token would be retrieved
// through Steamworks by making an ISteamUser::GetAuthSessionTicket() request.
// See https://partner.steamgames.com/doc/webapi_overview/auth for more information.
credentials.userAuthToken = "...";

// The result returned from this function call describes whether the login
// request was able to be initiated at all. If it was not, the result code
// represents the reason that the call failed, and the provided callback
// will not be called.
FGCSDK_Auth_ResultCode result = FGCSDK_Auth_Login(
&credentials,
[](const FGCSDK_Auth_LoginCallbackInfo* info)
{
// This function is called once the login request completes.
// info.authResult holds the result. If the returned result
// is successful, the user is logged into the FACEIT Client
// SDK, and the functionality of the SDK's interfaces is
// available for use.
},
nullptr
);

User Upgrade

If the current user's authentication credentials are not recognised by the FACEIT backend, a guest account is created for the user. Guest accounts are anonymous and have limited functionality, but allow players to use the FACEIT platform without the friction of account sign-up.

The user may upgrade their guest account to a full FACEIT account, or may merge it into an exiting FACEIT account that they already own. To begin this process, calling the FGCSDK_Auth_GetAccountUpgradeURL() function will return a URL that should be loaded into the user's web browser. When calling this function, the deepLink parameter may be used to embed a redirection URL, which the upgrade process will invoke at the end of the flow to re-open the game. For example, steam://run/{YourGameId} may be used to re-open a Steam game using the steam:// protocol.

Once the auth flow is complete and the game has been re-opened, the FGCSDK_Auth_CompleteAccountUpgrade() function should be called to instruct the SDK to finalise the upgrade process. This will automatically re-authenticate the user and allow them access to the full suite of FACEIT account features within the game.

#include "FACEITGameClientSDK/Auth/Auth.h"
#include "FACEITGameClientSDK/Utility/StringHelpers.h"

std::string MyGameClientInstance::GetUserUpgradeURL()
{
FGCSDK_Auth_GetAccountUpgradeURLData data {};

// This deep link can be whatever is most appropriate for your game.
data.deepLink = "steam://run/12345678";

// Fetch the URL.
return FGCSDK_ToString(&FGCSDK_Auth_GetAccountUpgradeURL, &data);
}

void MyGameClientInstance::CompleteUserUpgrade()
{
// Complete the account upgrade. The SDK must be polled
// regularly in order for this function to operate.
FGCSDK_Auth_ResultCode completionStarted = FGCSDK_Auth_CompleteAccountUpgrade(
[](const FGCSDK_Auth_CompleteUserUpgradeInfo* info)
{
std::cout << "Account upgrade " << (info->authResult == FGCSDK_AUTH_OK ? "succeeded" : "failed");
std::cout << "Is user upgraded: " << (info->userUpgraded ? "true" : "false");
},
nullptr);
}

Server SDK Configuration

Contrary to game clients, server applications are expected to be private, trusted applications that are under the control of the game developer. The server SDK's Auth interface must be provided with your game's API key before any other interfaces will function. This key can be found in your game's settings pages on the FACEIT Labs portal.

#include "FACEITGameServerSDK/Auth/Auth.h"

FGSSDK_Auth_SetToken("my-game-auth-token");