Skip to content

Commit d65ed20

Browse files
paulhazenWispyMouse
authored andcommitted
feat: Enable display and edit of encryption key for client credentials.
1 parent d8adee4 commit d65ed20

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

Assets/Plugins/Source/Editor/EditorWindows/EOSEditorWindow.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ public RetainPreference(string key)
103103
/// </summary>
104104
protected static Font MonoFont;
105105

106+
protected EOSEditorWindow(bool needsInitialization) : this("")
107+
{
108+
_initialized = !needsInitialization;
109+
}
110+
106111
protected EOSEditorWindow(string windowTitle, float minimumHeight = 50f, float minimumWidth = 50f,
107112
string preferencesOverrideKey = null)
108113
{
@@ -120,23 +125,23 @@ protected EOSEditorWindow(string windowTitle, float minimumHeight = 50f, float m
120125
/// <summary>
121126
/// String value for the title of the window.
122127
/// </summary>
123-
public string WindowTitle { get; }
128+
public string WindowTitle { get; protected set; }
124129

125130
protected virtual void OnEnable()
126131
{
127132
_initializeTask = Initialize();
128133
EditorApplication.update += CheckForInitialized;
129134
}
130135

131-
private void OnDisable()
136+
protected virtual void OnDisable()
132137
{
133138
EditorApplication.update -= CheckForInitialized;
134139
}
135140

136141
/// <summary>
137142
/// Checks to see if the windows has been initialized.
138143
/// </summary>
139-
private void CheckForInitialized()
144+
protected void CheckForInitialized()
140145
{
141146
if (!_initializeTask.IsCompleted || _initialized)
142147
{
@@ -246,7 +251,7 @@ protected void SetIsEmbedded(bool? isEmbedded = null)
246251
/// <summary>
247252
/// Called by Unity to render the window. Should not be overridden by deriving classes.
248253
/// </summary>
249-
public void OnGUI()
254+
public virtual void OnGUI()
250255
{
251256
// don't do anything if not initialized
252257
if (!_initialized)

Assets/Plugins/Source/Editor/Utility/GUIEditorUtility.cs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace PlayEveryWare.EpicOnlineServices.Editor.Utility
3131
#endif
3232

3333
using EpicOnlineServices.Utility;
34+
using PlayEveryWare.EpicOnlineServices.Editor.Windows;
3435
using System;
3536
using System.Collections.Generic;
3637
using System.Globalization;
@@ -539,6 +540,11 @@ public static float MeasureLongestLabelWidth(List<string> labels)
539540
return MeasureLabelWidth(longestString);
540541
}
541542

543+
public static float MeasureLabelWidth(int characters)
544+
{
545+
return MeasureLabelWidth(new string('0', characters));
546+
}
547+
542548
public static float MeasureLabelWidth(string label)
543549
{
544550
return new GUIStyle(GUI.skin.label).CalcSize(new GUIContent(label)).x;
@@ -1004,9 +1010,9 @@ private static SetOfNamed<EOSClientCredentials> RenderInput(ConfigFieldAttribute
10041010
"Enter your client information here as it appears in the Epic Dev Portal.",
10051011
"https://dev.epicgames.com/docs/dev-portal/product-management#clients",
10061012
clientCredentialsCopy,
1007-
(rect, item, nameAsLabel) =>
1013+
(rect, item, nameAsLabel) => // Things function renders input for a EOSClientCredential item.
10081014
{
1009-
float remainingWidth = rect.width;
1015+
float remainingWidth = rect.width - 5f;
10101016
float firstFieldWidth = (rect.width - 5f) * 0.18f;
10111017

10121018
if (nameAsLabel)
@@ -1034,25 +1040,49 @@ private static SetOfNamed<EOSClientCredentials> RenderInput(ConfigFieldAttribute
10341040

10351041
item.Value ??= new();
10361042

1043+
const float keyButtonWidth = 40f;
10371044
float clientFieldWidth = remainingWidth * 0.34f;
1038-
float clientIdFieldX = rect.x + firstFieldWidth + 5f;
1039-
remainingWidth -= clientFieldWidth;
1045+
float renderCursorX = rect.x + firstFieldWidth + 5f;
1046+
remainingWidth -= clientFieldWidth - 10f + keyButtonWidth;
10401047

10411048
item.Value.ClientId = RenderFieldWithHint(
10421049
EditorGUI.TextField,
1043-
new Rect(clientIdFieldX, rect.y, clientFieldWidth, rect.height),
1050+
new Rect(renderCursorX, rect.y, clientFieldWidth, rect.height),
10441051
string.IsNullOrEmpty,
10451052
item.Value.ClientId,
10461053
"Client ID"
10471054
);
10481055

1056+
renderCursorX += clientFieldWidth + 5f;
10491057
item.Value.ClientSecret = RenderFieldWithHint(
10501058
EditorGUI.TextField,
1051-
new Rect(rect.x + firstFieldWidth + 5f + clientFieldWidth + 5f, rect.y, remainingWidth - 10f,
1059+
new Rect(renderCursorX, rect.y, remainingWidth - 20f,
10521060
rect.height),
10531061
string.IsNullOrEmpty,
10541062
item.Value.ClientSecret,
10551063
"Client Secret");
1064+
1065+
GUIContent keyButtonContent = CreateGUIContent("Key", "Click to view or edit encryption key for client credentials");
1066+
renderCursorX += remainingWidth - 20f + 5f;
1067+
if (GUI.Button(
1068+
new Rect(renderCursorX, rect.y, keyButtonWidth, rect.height),
1069+
keyButtonContent))
1070+
{
1071+
ClientCredentialsEncryptionKeyWindow.Show(item.Value.EncryptionKey,
1072+
result =>
1073+
{
1074+
item.Value.EncryptionKey = result;
1075+
},
1076+
toValidate =>
1077+
{
1078+
return EOSClientCredentials.IsEncryptionKeyValid(toValidate);
1079+
},
1080+
"Client Credentials Encryption Key",
1081+
"Enter the encryption key for these client credentials here:"
1082+
);
1083+
}
1084+
1085+
10561086
},
10571087
() => clientCredentialsCopy.Add(),
10581088
(item) =>

com.playeveryware.eos/Runtime/Core/EOS_SDK_Additions/EOSClientCredentials.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class EOSClientCredentials : IEquatable<EOSClientCredentials>
3535
{
3636
public string ClientId;
3737
public string ClientSecret;
38-
public string EncryptionKey { get; private set; }
38+
public string EncryptionKey { get; set; }
3939

4040
private static readonly Regex s_invalidEncryptionKeyRegex;
4141

@@ -45,13 +45,18 @@ static EOSClientCredentials()
4545
}
4646

4747
public EOSClientCredentials()
48+
{
49+
EncryptionKey = GenerateEncryptionKey();
50+
}
51+
52+
public static string GenerateEncryptionKey()
4853
{
4954
// Randomly generate a 32 byte hex key
5055
byte[] randomBytes = new byte[32];
5156
using RandomNumberGenerator rng = RandomNumberGenerator.Create();
5257
rng.GetBytes(randomBytes);
5358

54-
EncryptionKey = BitConverter.ToString(randomBytes).Replace(
59+
return BitConverter.ToString(randomBytes).Replace(
5560
"-", string.Empty);
5661
}
5762

0 commit comments

Comments
 (0)