int UTestCloudDeploymentMenuWidget::AuthAndGetToken()

in GameLiftPlugin/Source/GameLiftClient/Private/UI/TestCloudDeploymentMenuWidget.cpp [162:221]


int UTestCloudDeploymentMenuWidget::AuthAndGetToken()
{
#if WITH_GAMELIFT_CLIENT
	auto sessionLogger = [](unsigned int InLevel, const char* InMessage, int InSize)
	{
		if (InLevel == GameLift::Logger::Level::Error)
		{
			sGlobalLoggerError = InMessage;
		}
		UE_LOG(TestCloudDeployment, Log, TEXT("Session manager logger: %s"), UTF8_TO_TCHAR(InMessage));
	};

	auto ConfigFileFullPath = FPaths::ConvertRelativePathToFull(FPaths::Combine(FPaths::ProjectContentDir(), ConfigFilePath));

	if (!FPaths::FileExists(ConfigFileFullPath))
	{
		LatestError = FString::Printf(TEXT("A config file is not found, make sure to setup it at: %s"), *ConfigFileFullPath);
		return GameLift::GAMELIFT_ERROR_GENERAL;
	}

	auto SessionManagerHandle = GameLiftSessionManagerInstanceCreate(StringCast<ANSICHAR>(*ConfigFileFullPath).Get(), sessionLogger);

	auto CallbackFunc = [](DISPATCH_RECEIVER_HANDLE InDispatchReceiver, const char* InCharPtr)
	{
		*(static_cast<FString *>(InDispatchReceiver)) = InCharPtr;
	};

	const std::string& _Username = StringCast<ANSICHAR>(*Username).Get();
	const std::string& _Password = StringCast<ANSICHAR>(*Password).Get();

	auto result = GameLiftAuthByUsernamePassword(SessionManagerHandle, _Username.c_str(), _Password.c_str());

	if (result == GameLift::GAMELIFT_SUCCESS)
	{
		GameLiftGetTokenId(SessionManagerHandle, &IdToken, CallbackFunc);

		if (GameLiftSessionManagerAreSettingsLoaded(SessionManagerHandle, GameLift::FeatureType::Identity))
		{
			result = GameLiftGetIdentityApiGatewayURL(SessionManagerHandle, &ApiGatewayEndpoint, CallbackFunc);
		}
	}

	GameLiftSessionManagerInstanceRelease(SessionManagerHandle);

	if (result != GameLift::GAMELIFT_SUCCESS)
	{
		return result;
	}

	if (ApiGatewayEndpoint.IsEmpty() || IdToken.IsEmpty())
	{
		return GameLift::GAMELIFT_ERROR_NO_ID_TOKEN;
	}

	return result;

#else
	return 0;
#endif
}