Skip to content

Commit

Permalink
fix(auth): add username ui, env perms request
Browse files Browse the repository at this point in the history
  • Loading branch information
mwfarb committed Nov 18, 2024
1 parent f5737ea commit e1bb27d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 39 deletions.
68 changes: 40 additions & 28 deletions Runtime/ArenaClientEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,49 @@ public override void OnInspectorGUI()
DrawDefaultInspector();

// add readonly auth results
GUILayout.Space(5f);
EditorGUILayout.LabelField("Authentication", EditorStyles.boldLabel);

if (!string.IsNullOrWhiteSpace(script.username))
{
GUILayout.BeginHorizontal("Box");
GUILayout.Label("Username");
GUILayout.FlexibleSpace();
GUILayout.Label(script.username);
GUILayout.EndHorizontal();
}
if (!string.IsNullOrWhiteSpace(script.email))
{
GUILayout.BeginHorizontal("Box");
GUILayout.Label("Email");
GUILayout.FlexibleSpace();
GUILayout.Label(script.email);
GUILayout.EndHorizontal();
}
if (!string.IsNullOrWhiteSpace(script.permissions))
{
GUILayout.Space(5f);
EditorGUILayout.LabelField("Authentication", EditorStyles.boldLabel);

if (!string.IsNullOrWhiteSpace(script.email))
{
GUILayout.BeginHorizontal("Box");
GUILayout.Label("Email");
GUILayout.FlexibleSpace();
GUILayout.Label(script.email);
GUILayout.EndHorizontal();
}
if (!string.IsNullOrWhiteSpace(script.permissions))
{
GUILayout.BeginVertical("Box");
GUILayout.Label("Permissions");
scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(Mathf.Infinity), GUILayout.Height(250));
GUILayout.Label(script.permissions);
GUILayout.EndScrollView();
GUILayout.EndVertical();
}
if (script.mqttExpires > 0)
{
GUIStyle style = new GUIStyle(GUI.skin.label);
style.richText = true;
DateTimeOffset dateTimeOffSet = DateTimeOffset.FromUnixTimeSeconds(script.mqttExpires);
TimeSpan duration = dateTimeOffSet.DateTime.Subtract(DateTime.Now.ToUniversalTime());
GUILayout.Label($"Expires in {ArenaUnity.TimeSpanToString(duration)}", style);
}
GUILayout.BeginVertical("Box");
GUILayout.Label("Permissions");
scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(Mathf.Infinity), GUILayout.Height(250));
GUILayout.Label(script.permissions);
GUILayout.EndScrollView();
GUILayout.EndVertical();
}
else
{
GUILayout.Label("Permissions granted appear in Play mode.");
}
if (script.mqttExpires > 0)
{
GUIStyle style = new GUIStyle(GUI.skin.label);
style.richText = true;
DateTimeOffset dateTimeOffSet = DateTimeOffset.FromUnixTimeSeconds(script.mqttExpires);
TimeSpan duration = dateTimeOffSet.DateTime.Subtract(DateTime.Now.ToUniversalTime());
GUILayout.Label($"Expires in {ArenaUnity.TimeSpanToString(duration)}", style);
}
EditorGUILayout.LabelField("Additional Rights", EditorStyles.boldLabel);
script.requestRemoteRenderRights = EditorGUILayout.Toggle("Request Remote Render Host Rights", script.requestRemoteRenderRights);
script.requestEnvironmentRights = EditorGUILayout.Toggle("Request Environment Host Rights", script.requestEnvironmentRights);
}
}
#endif
Expand Down
3 changes: 1 addition & 2 deletions Runtime/ArenaClientScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,14 +1445,13 @@ public void ProcessMessage(string topic, string message)
case "o":
// handle scene objects, user objects, user presense
ArenaObjectJson msg = JsonConvert.DeserializeObject<ArenaObjectJson>(message);
Debug.Log(message);
StartCoroutine(ProcessArenaMessage(msg));
break;
case "r": // remote render handled by arena-renderfusion package currently
case "c": // chat not implemented in unity currently
case "p": // program not implemented in unity currently
case "e": // environment not implemented in unity currently
case "d": // debig not implemented in unity currently
case "d": // debug not implemented in unity currently
break;
default:
// ????
Expand Down
2 changes: 2 additions & 0 deletions Runtime/ArenaMqttAuthIdsJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class ArenaMqttAuthIdsJson
public string camid { get; set; }
public string handleftid { get; set; }
public string handrightid { get; set; }
public string renderfusionid { get; set; }
public string environmentid { get; set; }

// General json object management
[OnError]
Expand Down
42 changes: 33 additions & 9 deletions Runtime/ArenaMqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public class ArenaMqttClient : M2MqttUnityClient
/// </summary>
public long mqttExpires { get; private set; }

/// <summary>
/// Manual request for remote render "r" rights, pending account allowances.
/// </summary>
public bool requestRemoteRenderRights { get; set; }
/// <summary>
/// Manual request for environment "e" rights, pending account allowances.
/// </summary>
public bool requestEnvironmentRights { get; set; }

// internal variables
private string idToken = null;
protected string csrfToken = null;
Expand All @@ -66,6 +75,7 @@ public class ArenaMqttClient : M2MqttUnityClient
private const string packageNameRenderFusion = "io.conix.arena.renderfusion";

public string appFilesPath { get; private set; }
public string username { get; private set; }
public string userid { get; private set; }
public string userclient { get; private set; }
public string camid { get; private set; }
Expand Down Expand Up @@ -253,14 +263,13 @@ private IEnumerator Signin(string sceneName, string namespaceName, string realm,
else
{
string tokenType = "";
string userName = "";
switch (authType)
{
case Auth.Anonymous:
// prefix all anon users with "anonymous-"
Debug.Log("Using anonymous MQTT token.");
tokenType = "anonymous";
userName = $"anonymous-unity";
username = $"anonymous-unity";
break;
case Auth.Google:
// get oauth app credentials
Expand Down Expand Up @@ -320,7 +329,7 @@ private IEnumerator Signin(string sceneName, string namespaceName, string realm,
authState = JsonConvert.DeserializeObject<ArenaUserStateJson>(cd.result.ToString());
if (authState.authenticated)
{
userName = authState.username;
username = authState.username;
}
if (string.IsNullOrWhiteSpace(namespaceName))
{
Expand All @@ -336,11 +345,14 @@ private IEnumerator Signin(string sceneName, string namespaceName, string realm,

// get arena user mqtt token
form.AddField("id_auth", tokenType);
form.AddField("username", userName);
// always request user-specific context, esp. for remote rendering
form.AddField("username", username);
// always request user-specific context
form.AddField("client", "unity");
form.AddField("userid", "true");
form.AddField("camid", "true");
if (hasArenaCamera)
{
form.AddField("camid", "true");
}
if (!string.IsNullOrWhiteSpace(realm))
{
form.AddField("realm", realm);
Expand All @@ -350,16 +362,28 @@ private IEnumerator Signin(string sceneName, string namespaceName, string realm,
{
form.AddField("scene", $"{namespaceName}/{sceneName}");
}
// manual rights requests
if (requestRemoteRenderRights)
{
form.AddField("renderfusionid", "true");
}
if (requestEnvironmentRights)
{
form.AddField("environmentid", "true");
}
#if UNITY_EDITOR
// test for render fusion, request permissions if so
// auto-test for render fusion, request permissions if so
if (packageListRequest.IsCompleted)
{
if (packageListRequest.Status == StatusCode.Success)
foreach (var package in packageListRequest.Result)
if (package.name == packageNameRenderFusion)
{
form.AddField("renderfusionid", "true");
else if (packageListRequest.Status >= StatusCode.Failure)
Debug.LogWarning(packageListRequest.Error.message);
requestRemoteRenderRights = true; // for display purposes
}
else if (packageListRequest.Status >= StatusCode.Failure)
Debug.LogWarning(packageListRequest.Error.message);
}
else
{
Expand Down

0 comments on commit e1bb27d

Please sign in to comment.