Unity Authentication Service in Unreal
You can use the Unity Authentication Service (UAS) in your Unreal Vivox application.
Requirements
- Unreal Engine version 5.1.1 or later
- A Unity account
- The Unity Gaming Services SDK for Unreal Engine
Integration steps
- Ensure you have a compatible version of the Unreal Engine for the Unity Gaming Services for Unreal Plugin. Refer to the SDK page in the Unreal Marketplace for more information.
- Go to the Unity Gaming Services SDK for Unreal Engine Unreal Engine Marketplace page in your Epic Games Launcher, or select Open in Launcher from the linked Marketplace page.
- Load the plug-in into your project on the Epic Games Launcher Marketplace page.
- Go into your Project Settings and locate the Unity Authentication plug-in settings.
- Place the Project ID from your Project page on the Unity Dashboard into the Project ID field. The setting will likely autoformat. Place the target environment name in the Environment Name field.
Note: Find your Project ID and Environment on the Unity Dashboard, by selecting the Projects tab and then the project you’re working on.
Authenticate with the Unity Authentication Service
Use the following instructions to set up the Unity Authentication Subsystem to sign-in to Vivox:
Add Authentication to the PublicDependencyModuleName in your project’s build.cs file
- Once you install the plug-in and assign settings in your project, you can set up and une the
AuthenticationSubsystem
in C++.
- Once you install the plug-in and assign settings in your project, you can set up and une the
Get the UGameInstance from the GameWorld and assign the AuthenticationSubsystem to a variable from the GameInstance.
UWorld* GameWorld = GetWorld(); UGameInstance* GameInstance = GameWorld->GetGameInstance(); UAuthenticationSubsystem* AuthenticationSubsystem = GameInstance->GetSubsystem<UAuthenticationSubsystem>();
Set up an
AuthenticationResponse
UFunction, namedOnAuthentication
in the following example, to track when the Authentication has finished successfully. Then, pass it into SignInAnonymously, along with anyFAuthenticationSignInOptions
you need.Unity::Services::Core::THandler<FAuthenticationResponse> authenticationResponse; FName OnAuthenticationFName("OnAuthentication"); authenticationResponse.BindUFunction(this, OnAuthenticationFName); FAuthenticationSignInOptions signInOptions; AuthenticationSubsystem->SignInAnonymously(signInOptions, authenticationResponse);
After Authentication has successfully authenticated to the UGS Service, replace the LoginToken in any
LoginSession.BeginLogin
call with the AuthenticationSubsystem->GetAccessToken(). Below is an example:LoginSession.BeginLogin(WebService, AuthenticationSubsystem->GetAccessToken(), SubscriptionMode::Accept, TSet<AccountId>(), TSet<AccountId>(), TSet<AccountId>(), OnBeginLoginCompleteCallback);
Note: When using Unity Authentication Access Tokens, the local AccountID’s Account Name should be the same as the Authentication PlayerID, as shown here:
//This is being done in OnAuthentication, using the returned FAuthenticationResponse as response AccountId m_Account = AccountId(m_tokenIssuer, response.UserId, m_domain)
You can also use Authentication Tokens in place of ChannelSession
connect tokens, as shown in the following example:
ChannelSession.BeginConnect(true, false, true, AuthenticationSubsystem->GetAccessToken(), OnBeginConnectCompleteCallback);