Skip to main content

Unreal Engine Module - Login with Steam - Use the Online Subsystem to log in with Steam

Last updated on January 13, 2024

Unwrap The Subsystem

In the Module: Login with Device ID, you have set up a subsystem in the AuthEssentialsSubsystem_Starter class for login with device ID. Since login with Steam has similar logic, you will reuse that subsystem. Let's recall some of the subsystem's functionalities.

  1. If you open the AuthEssentialsSubsystem_Starter class CPP file located in /Source/AccelByteWars/TutorialModules/Access/AuthEssentials/AuthEssentialsSubsystem_Starter.cpp, you will find the following SetAuthCredentials() function. You use this function to set up login credentials, including the login method, id/username, and token/password.

    void UAuthEssentialsSubsystem_Starter::SetAuthCredentials(const EAccelByteLoginType& LoginMethod, const FString& Id, const FString& Token) 
    {
    Credentials.Type = (LoginMethod == EAccelByteLoginType::None) ? TEXT("") : FAccelByteUtilities::GetUEnumValueAsString(LoginMethod);
    Credentials.Id = Id;
    Credentials.Token = Token;
    }
  2. After you set up the credentials, you can call the Login() function to start the login process. The credentials supplied through the above SetAuthCredentials() method will be passed to the underlying login call made to the AccelByte OnlineSubsystem.

    void UAuthEssentialsSubsystem_Starter::Login(const APlayerController* PC, const FAuthOnLoginCompleteDelegate& OnLoginComplete)
    {
    if (!ensure(IdentityInterface.IsValid()))
    {
    FString Message = TEXT("Cannot login. Identiy interface is not valid.");
    UE_LOG_AUTH_ESSENTIALS(Warning, TEXT("%s"), *Message);
    OnLoginComplete.ExecuteIfBound(false, *Message);
    return;
    }

    // Get local user number
    const ULocalPlayer* LocalPlayer = PC->GetLocalPlayer();
    ensure(LocalPlayer != nullptr);
    int32 LocalUserNum = LocalPlayer->GetControllerId();

    // Perform login using IdentityInterface
    IdentityInterface->AddOnLoginCompleteDelegate_Handle(LocalUserNum, FOnLoginCompleteDelegate::CreateUObject(this, &ThisClass::OnLoginComplete, OnLoginComplete));
    IdentityInterface->Login(LocalUserNum, Credentials);

    // Helper to logout the user when the game shutdown in PIE mode.
    if (UAccelByteWarsGameInstance* ByteWarsGameInstance = Cast<UAccelByteWarsGameInstance>(GetGameInstance()); ensure(ByteWarsGameInstance))
    {
    ByteWarsGameInstance->OnGameInstanceShutdownDelegate.AddWeakLambda(this, [this, LocalUserNum]()
    {
    IdentityInterface->Logout(LocalUserNum);

    UE_LOG_AUTH_ESSENTIALS(Warning, TEXT("Logging out local player %d"), LocalUserNum);
    });
    }
    }
  3. In the Module: Login with Device ID, the above functions were utilized to implement login using device ID. Those same two functions will be used to log in with Steam in the next section.

  4. Now, you can move to the next tutorial section to connect the UI you prepared earlier with the AuthEssentialsSubsystem_Starter subsystem.

Resources