Skip to content

Commit

Permalink
Use login token from its new home.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Nov 29, 2023
1 parent c394804 commit 9298aee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Editor/CesiumIonServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public CesiumIonSession GetSession(CesiumIonServer server)
return session;
}

private string GetUserAccessToken(CesiumIonServer server)
internal string GetUserAccessToken(CesiumIonServer server)
{
int index = this._userAccessTokenMap.FindIndex(record => record.server == server);
return index >= 0 ? this._userAccessTokenMap[index].token : null;
}

private void SetUserAccessToken(CesiumIonServer server, string token)
internal void SetUserAccessToken(CesiumIonServer server, string token)
{
int index = this._userAccessTokenMap.FindIndex(record => record.server == server);
if (index >= 0)
Expand Down
5 changes: 5 additions & 0 deletions Editor/ConfigureReinterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public void ExposeToCPP()

CesiumIonSession session = CesiumIonSession.Ion();
session.IsConnected();
CesiumIonServer server = session.server;
session.server = server;

CesiumIonServerManager.instance.GetUserAccessToken(null);
CesiumIonServerManager.instance.SetUserAccessToken(null, null);

EditorPrefs.HasKey("Key");
EditorPrefs.GetString("Key");
Expand Down
26 changes: 15 additions & 11 deletions native~/Editor/src/CesiumIonSessionImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
#include "UnityAssetAccessor.h"
#include "UnityTaskProcessor.h"

#include <DotNet/CesiumForUnity/CesiumIonServer.h>
#include <DotNet/CesiumForUnity/CesiumIonServerManager.h>
#include <DotNet/CesiumForUnity/CesiumIonSession.h>
#include <DotNet/CesiumForUnity/CesiumRuntimeSettings.h>
#include <DotNet/UnityEditor/EditorPrefs.h>
#include <DotNet/UnityEngine/Application.h>

using namespace DotNet;

namespace CesiumForUnityNative {

const std::string CesiumIonSessionImpl::_userAccessTokenEditorKey =
"CesiumUserAccessToken";

CesiumIonSessionImpl& CesiumIonSessionImpl::ion() {
return CesiumForUnity::CesiumIonSession::Ion().NativeImplementation();
}
Expand Down Expand Up @@ -121,12 +119,14 @@ void CesiumIonSessionImpl::Connect(
this->_authorizeUrl = url;
UnityEngine::Application::OpenURL(url);
})
.thenInMainThread([this](CesiumIonClient::Connection&& connection) {
.thenInMainThread([this,
session](CesiumIonClient::Connection&& connection) {
this->_isConnecting = false;
this->_connection = std::move(connection);

UnityEditor::EditorPrefs::SetString(
CesiumIonSessionImpl::_userAccessTokenEditorKey,
CesiumForUnity::CesiumIonServer server = session.server();
CesiumForUnity::CesiumIonServerManager::instance().SetUserAccessToken(
server,
this->_connection.value().getAccessToken());
this->broadcastConnectionUpdate();
})
Expand All @@ -144,8 +144,10 @@ void CesiumIonSessionImpl::Resume(
return;
}

System::String userAccessToken = UnityEditor::EditorPrefs::GetString(
CesiumIonSessionImpl::_userAccessTokenEditorKey);
CesiumForUnity::CesiumIonServer server = session.server();
System::String userAccessToken =
CesiumForUnity::CesiumIonServerManager::instance().GetUserAccessToken(
server);

if (System::String::Equals(userAccessToken, System::String(""))) {
// No user access token was stored, so there's no existing session to
Expand Down Expand Up @@ -185,8 +187,10 @@ void CesiumIonSessionImpl::Disconnect(
this->_assets.reset();
this->_tokens.reset();

UnityEditor::EditorPrefs::DeleteKey(
CesiumIonSessionImpl::_userAccessTokenEditorKey);
CesiumForUnity::CesiumIonServer server = session.server();
CesiumForUnity::CesiumIonServerManager::instance().SetUserAccessToken(
server,
nullptr);

this->broadcastConnectionUpdate();
this->broadcastAssetsUpdate();
Expand Down

0 comments on commit 9298aee

Please sign in to comment.