Skip to main content
Authenticating

Online Subsystem Login (C++)

warning

Requires EOSCore 2.2.0 and later.

The Login node and the -AUTH_TYPE= command line login both call Login() on the EOSCore identity interface. You can call it yourself from C++:

#include "OnlineSubsystem.h"
#include "OnlineSubsystemUtils.h"
#include "Interfaces/OnlineIdentityInterface.h"

IOnlineIdentityPtr Identity = Online::GetSubsystem(GetWorld(), TEXT("EOSCore"))->GetIdentityInterface();
Identity->AddOnLoginCompleteDelegate_Handle(0, FOnLoginCompleteDelegate::CreateUObject(this, &UMyGameInstance::OnLoginComplete));
Identity->Login(0, FOnlineAccountCredentials(TEXT("deviceid"), TEXT("Player Name"), FString()));

Login types​

FOnlineAccountCredentials::Type has the form <LoginType>|<CredentialsType>|<LoginData>. Each part can be a number or a name, and names are not case sensitive. You can leave out the parts you don't need.

LoginType nameNumberLogin method
password0Email and password. Deprecated in the EOS SDK, it always fails
exchangecode1Exchange code from the Epic Games Launcher
persistentauth, autologin2Previous login on this computer, see Persistent Auth
devicecode3Device code
developer, devtool4DevTool. Id is the host (localhost:6546), Token the credential name
refreshtoken5Refresh token, see Refresh Token
accountportal, portal6Account Portal (EOS overlay or browser)
externalauth, external7External auth

The login types above log in with an Epic Account (Auth interface) and then with Connect. The CredentialsType selects a Connect login with an external account instead:

CredentialsType nameNumber
epic0, the default: Epic Account login with the LoginType
steamappticket1
psn, xbl, discord, gog, nintendo, nintendonsa, uplay, openid2 to 9
deviceid10. Id is the display name. A DeviceId is created when the device has none
apple, google, oculus, itchiojwt, itchiokey, epicidtoken, amazon11 to 17
steamsessionticket18
viveport19

A Type that is only a credential name other than epic, for example deviceid or steamsessionticket, selects that Connect login.

For external credential types, LoginData is the token from the platform. When LoginData is empty, Token is used. On the Login node, LoginData is Additional Data and Token is Password.

TypeLogin
accountportalAccount Portal
developerDevTool
deviceidDeviceId
steamsessionticketSteam session ticket in Token
0|9|<token>OpenID access token in LoginData

Several local players​

Every local user number keeps its own Epic Account Id and Product User Id. Two local players can log in at the same time, each with Login(LocalUserNum, ...), and functions that take a local user number return that player's ids.

A failed login calls OnLoginComplete with bWasSuccessful = false. The user is not logged out.

Refreshing external tokens​

EOS asks for a new Connect login before the login of a local user expires. The plugin refreshes Epic Account, DeviceId and Steam session ticket logins itself. For a Steam session ticket, pass a new ticket with Update Steam Session Ticket first.

Tokens from other providers can only come from your game. When such a login is about to expire, FOnlineIdentityEOSCore::OnConnectAuthExpiring is called with the local user number and the credential type. Get a new token from the provider and call RefreshConnectLoginWithToken. If the refresh fails, the user is logged out. If nothing is bound to the delegate, a warning is logged and the login expires.

#include "OnlineIdentityEOSCore.h"

void UMyGameInstance::BindAuthExpiring()
{
IOnlineIdentityPtr Identity = Online::GetSubsystem(GetWorld(), TEXT("EOSCore"))->GetIdentityInterface();
TSharedPtr<FOnlineIdentityEOSCore, ESPMode::ThreadSafe> EOSIdentity = StaticCastSharedPtr<FOnlineIdentityEOSCore>(Identity);
EOSIdentity->OnConnectAuthExpiring.AddUObject(this, &UMyGameInstance::HandleConnectAuthExpiring);
}

void UMyGameInstance::HandleConnectAuthExpiring(int32 LocalUserNum, EOS_EExternalCredentialType CredentialType)
{
const FString NewToken = GetNewTokenFromMyProvider();

IOnlineIdentityPtr Identity = Online::GetSubsystem(GetWorld(), TEXT("EOSCore"))->GetIdentityInterface();
StaticCastSharedPtr<FOnlineIdentityEOSCore>(Identity)->RefreshConnectLoginWithToken(LocalUserNum, NewToken);
}

RefreshConnectLoginWithToken returns false when the user is not logged in with an external token or the token is empty. Add OnlineSubsystemEOSCore to the dependencies in your Build.cs to use FOnlineIdentityEOSCore.

OnConnectAuthExpiring and RefreshConnectLoginWithToken are C++ only. In Blueprint, listen for the expiration with the Connect nodes, see Refreshing Tokens.