Skip to content

Commit 90d7a09

Browse files
committed
Add support for white label login
1 parent 8acffba commit 90d7a09

10 files changed

+352
-8
lines changed

Runtime/Client/LootLockerBaseServerAPI.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace LootLocker.LootLockerEnums
1414
{
15-
public enum LootLockerCallerRole { User, Admin, Player };
15+
public enum LootLockerCallerRole { User, Admin, Player, Base };
1616
}
1717

1818
namespace LootLocker
@@ -47,6 +47,9 @@ public void SwitchURL(LootLocker.LootLockerEnums.LootLockerCallerRole mainCaller
4747
case LootLocker.LootLockerEnums.LootLockerCallerRole.Player:
4848
SERVER_URL = LootLockerConfig.current.playerUrl;
4949
break;
50+
case LootLocker.LootLockerEnums.LootLockerCallerRole.Base:
51+
SERVER_URL = LootLockerConfig.current.baseUrl;
52+
break;
5053
default:
5154
SERVER_URL = LootLockerConfig.current.url;
5255
break;

Runtime/Client/LootLockerConfig.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static LootLockerConfig Get()
2525
return settingsInstance;
2626
}
2727

28-
public static bool CreateNewSettings(string apiKey, string gameVersion, platformType platform, bool onDevelopmentMode, DebugLevel debugLevel = DebugLevel.Off, bool allowTokenRefresh = false)
28+
public static bool CreateNewSettings(string apiKey, string gameVersion, platformType platform, bool onDevelopmentMode, string domainKey, DebugLevel debugLevel = DebugLevel.Off, bool allowTokenRefresh = false)
2929
{
3030
settingsInstance = Resources.Load<LootLockerConfig>("Config/LootLockerConfig");
3131

@@ -38,6 +38,7 @@ public static bool CreateNewSettings(string apiKey, string gameVersion, platform
3838
settingsInstance.developmentMode = onDevelopmentMode;
3939
settingsInstance.currentDebugLevel = debugLevel;
4040
settingsInstance.allowTokenRefresh = allowTokenRefresh;
41+
settingsInstance.domainKey = domainKey;
4142

4243
return true;
4344
}
@@ -63,6 +64,8 @@ public static LootLockerConfig current
6364
[HideInInspector]
6465
public string adminToken;
6566
[HideInInspector]
67+
public string domainKey;
68+
[HideInInspector]
6669
public int gameID;
6770
public string game_version = "1.0";
6871
[HideInInspector]
@@ -78,6 +81,8 @@ public enum platformType { Android, iOS, Steam, PlayStationNetwork }
7881
public string playerUrl = "https://api.lootlocker.io/player";
7982
[HideInInspector]
8083
public string userUrl = "https://api.lootlocker.io/game";
84+
[HideInInspector]
85+
public string baseUrl = "https://api.lootlocker.io";
8186
public enum DebugLevel { All, ErrorOnly, NormalOnly, Off }
8287
public DebugLevel currentDebugLevel;
8388
public bool allowTokenRefresh = true;

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@ namespace LootLocker
77
public class LootLockerEndPoints
88
{
99
// Authentication
10-
[Header("Authentication Endpoints")]
10+
[Header("Authentication")]
1111
public static EndPointClass playerVerification = new EndPointClass("v1/player/verify", LootLockerHTTPMethod.POST);
1212
public static EndPointClass authenticationRequest = new EndPointClass("v2/session", LootLockerHTTPMethod.POST);
1313
public static EndPointClass guestSessionRequest = new EndPointClass("v2/session/guest", LootLockerHTTPMethod.POST);
14+
public static EndPointClass whiteLabelLoginSessionRequest = new EndPointClass("v2/session/white-label", LootLockerHTTPMethod.POST);
1415
public static EndPointClass endingSession = new EndPointClass("v1/session", LootLockerHTTPMethod.DELETE);
1516
public static EndPointClass initialAuthenticationRequest = new EndPointClass("v1/session", LootLockerHTTPMethod.POST);
1617
public static EndPointClass twoFactorAuthenticationCodeVerification = new EndPointClass("v1/2fa", LootLockerHTTPMethod.POST);
1718
public static EndPointClass subsequentRequests = new EndPointClass("v1/games", LootLockerHTTPMethod.GET);
1819

20+
// White Label Login
21+
[Header("White Label Login")]
22+
public static EndPointClass whiteLabelSignUp = new EndPointClass("white-label-login/sign-up", LootLockerHTTPMethod.POST);
23+
public static EndPointClass whiteLabelRequestPasswordReset = new EndPointClass("white-label-login/request-reset-password", LootLockerHTTPMethod.POST);
24+
public static EndPointClass whiteLabelRequestAccountVerification = new EndPointClass("white-label-login/request-verification", LootLockerHTTPMethod.POST);
25+
1926
// Player
20-
[Header("Player Endpoints")]
27+
[Header("Player")]
2128
public static EndPointClass getPlayerInfo = new EndPointClass("v1/player/info", LootLockerHTTPMethod.GET);
2229
public static EndPointClass getInventory = new EndPointClass("v1/player/inventory/list", LootLockerHTTPMethod.GET);
2330
public static EndPointClass getCurrencyBalance = new EndPointClass("v1/player/balance", LootLockerHTTPMethod.GET);
@@ -33,7 +40,7 @@ public class LootLockerEndPoints
3340
public static EndPointClass setPlayerName = new EndPointClass("player/name", LootLockerHTTPMethod.PATCH);
3441

3542
// Character
36-
[Header("Character Endpoints")]
43+
[Header("Character")]
3744
public static EndPointClass characterLoadouts = new EndPointClass("v1/player/character/loadout", LootLockerHTTPMethod.GET);
3845
public static EndPointClass getOtherPlayersCharacterLoadouts = new EndPointClass("v1/player/character/loadout/{0}?platform={1}", LootLockerHTTPMethod.GET);
3946
public static EndPointClass updateCharacter = new EndPointClass("v1/player/character/{0}", LootLockerHTTPMethod.PUT);

Runtime/Client/LootLockerServerRequest.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,34 @@ public class LootLockerResponse
6262

6363
}
6464

65+
/// <summary>
66+
/// Convenience factory class for creating some responses that we use often.
67+
/// </summary>
68+
public class LootLockerResponseFactory
69+
{
70+
/// <summary>
71+
/// Construct an error response to send to the client.
72+
/// </summary>
73+
public static T Error<T> (string errorMessage) where T : LootLockerResponse, new()
74+
{
75+
return new T()
76+
{
77+
success = false,
78+
hasError = true,
79+
Error = errorMessage,
80+
text = errorMessage
81+
};
82+
}
83+
84+
/// <summary>
85+
/// Construct an error response specifically when the SDK has not been initialized.
86+
/// </summary>
87+
public static T SDKNotInitializedError<T>() where T : LootLockerResponse, new()
88+
{
89+
return Error<T>("SDK not initialised");
90+
}
91+
}
92+
6593
/// <summary>
6694
/// Construct a request to send to the server.
6795
/// </summary>
@@ -115,6 +143,34 @@ public static void CallAPI(string endPoint, LootLockerHTTPMethod httpMethod, str
115143
});
116144
}
117145

146+
public static void CallDomainAuthAPI(string endPoint, LootLockerHTTPMethod httpMethod, string body = null, Action<LootLockerResponse> onComplete = null)
147+
{
148+
if (LootLockerConfig.current.domainKey.ToString().Length == 0)
149+
{
150+
#if UNITY_EDITOR
151+
LootLockerSDKManager.DebugMessage("LootLocker domain key must be set in settings", true);
152+
#endif
153+
onComplete?.Invoke(LootLockerResponseFactory.Error<LootLockerResponse>("LootLocker domain key must be set in settings"));
154+
155+
return;
156+
}
157+
158+
Dictionary<string, string> headers = new Dictionary<string, string>();
159+
headers.Add("domain-key", LootLockerConfig.current.domainKey);
160+
161+
if (LootLockerConfig.current.developmentMode)
162+
{
163+
headers.Add("is-development", "true");
164+
}
165+
166+
LootLockerBaseServerAPI.I.SwitchURL(LootLockerCallerRole.Base);
167+
168+
new LootLockerServerRequest(endPoint, httpMethod, body, headers, callerRole: LootLockerCallerRole.Base).Send((response) =>
169+
{
170+
onComplete?.Invoke(response);
171+
});
172+
}
173+
118174
public static void UploadFile(string endPoint, LootLockerHTTPMethod httpMethod, byte[] file, string fileName = "file", string fileContentType = "text/plain", Dictionary<string, string> body = null, Action<LootLockerResponse> onComplete = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User)
119175
{
120176
Dictionary<string, string> headers = new Dictionary<string, string>();

Runtime/Editor/ProjectSettings.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,38 @@ private void DrawGameSettings()
5656
{
5757
gameSettings.apiKey = m_CustomSettings.FindProperty("apiKey").stringValue;
5858
}
59+
var content = new GUIContent();
60+
content.text = "API key can be found in `Settings > Game settings > API` in the Web Console";
61+
EditorGUILayout.HelpBox(content, false);
62+
EditorGUILayout.Space();
63+
64+
EditorGUI.BeginChangeCheck();
65+
66+
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("domainKey"));
67+
if (EditorGUI.EndChangeCheck())
68+
{
69+
gameSettings.domainKey = m_CustomSettings.FindProperty("domainKey").stringValue;
70+
}
71+
var domainContent = new GUIContent();
72+
domainContent.text = "Domain key can be found in `Settings > Game settings > API` in the Web Console";
73+
EditorGUILayout.HelpBox(domainContent, false);
74+
EditorGUILayout.Space();
5975

6076
EditorGUI.BeginChangeCheck();
6177
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("game_version"));
6278
if (EditorGUI.EndChangeCheck())
6379
{
6480
gameSettings.game_version = m_CustomSettings.FindProperty("game_version").stringValue;
6581
}
82+
EditorGUILayout.Space();
6683

6784
EditorGUI.BeginChangeCheck();
6885
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("platform"));
6986
if (EditorGUI.EndChangeCheck())
7087
{
7188
gameSettings.platform = (LootLockerConfig.platformType)m_CustomSettings.FindProperty("platform").enumValueIndex;
7289
}
90+
EditorGUILayout.Space();
7391

7492
EditorGUI.BeginChangeCheck();
7593
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("developmentMode"));
@@ -78,6 +96,7 @@ private void DrawGameSettings()
7896
{
7997
gameSettings.developmentMode = m_CustomSettings.FindProperty("developmentMode").boolValue;
8098
}
99+
EditorGUILayout.Space();
81100

82101
EditorGUI.BeginChangeCheck();
83102
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("currentDebugLevel"));
@@ -86,6 +105,7 @@ private void DrawGameSettings()
86105
{
87106
gameSettings.currentDebugLevel = (LootLockerConfig.DebugLevel)m_CustomSettings.FindProperty("currentDebugLevel").enumValueIndex;
88107
}
108+
EditorGUILayout.Space();
89109

90110
EditorGUI.BeginChangeCheck();
91111
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("allowTokenRefresh"));
@@ -94,6 +114,7 @@ private void DrawGameSettings()
94114
{
95115
gameSettings.allowTokenRefresh = m_CustomSettings.FindProperty("allowTokenRefresh").boolValue;
96116
}
117+
EditorGUILayout.Space();
97118
}
98119

99120
[SettingsProvider]

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ static bool Init()
2626
return LoadConfig();
2727
}
2828

29-
public static bool Init(string apiKey, string gameVersion, platformType platform, bool onDevelopmentMode)
29+
public static bool Init(string apiKey, string gameVersion, platformType platform, bool onDevelopmentMode, string domainKey)
3030
{
3131
DebugMessage("SDK is Intializing");
3232
LootLockerServerManager.CheckInit();
33-
return LootLockerConfig.CreateNewSettings(apiKey, gameVersion, platform, onDevelopmentMode);
33+
return LootLockerConfig.CreateNewSettings(apiKey, gameVersion, platform, onDevelopmentMode, domainKey);
3434
}
3535

3636
static bool LoadConfig()
@@ -196,6 +196,27 @@ public static void StartSteamSession(string steamId64, Action<LootLockerSessionR
196196
LootLockerAPIManager.Session(sessionRequest, onComplete);
197197
}
198198

199+
/// <summary>
200+
/// Create new user using the white label login system.
201+
///
202+
/// White label platform must be enabled in the web console for this to work.
203+
/// </summary>
204+
public static void StartWhiteLabelSession(string email, string password, Action<LootLockerSessionResponse> onComplete)
205+
{
206+
if (!CheckInitialized())
207+
{
208+
LootLockerSessionResponse response = new LootLockerSessionResponse();
209+
response.success = false;
210+
response.hasError = true;
211+
response.Error = "SDk not initialised";
212+
response.text = "SDk not initialised";
213+
onComplete?.Invoke(response);
214+
return;
215+
}
216+
LootLockerWhiteLabelSessionRequest sessionRequest = new LootLockerWhiteLabelSessionRequest(email, password);
217+
LootLockerAPIManager.WhiteLabelSession(sessionRequest, onComplete);
218+
}
219+
199220
public static void EndSession(string deviceId, Action<LootLockerSessionResponse> onComplete)
200221
{
201222
if (!CheckInitialized())
@@ -213,6 +234,65 @@ public static void EndSession(string deviceId, Action<LootLockerSessionResponse>
213234
}
214235
#endregion
215236

237+
#region White Label Login
238+
239+
/// <summary>
240+
/// Create new user using the white label login system.
241+
///
242+
/// White label platform must be enabled in the web console for this to work.
243+
/// </summary>
244+
public static void WhiteLabelSignUp(string email, string password, Action<LootLockerWhiteLabelSignupResponse> onComplete)
245+
{
246+
if (!CheckInitialized())
247+
{
248+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerWhiteLabelSignupResponse>());
249+
return;
250+
}
251+
252+
LootLockerWhiteLabelUserRequest input = new LootLockerWhiteLabelUserRequest
253+
{
254+
email = email,
255+
password = password
256+
};
257+
258+
LootLockerAPIManager.WhiteLabelSignUp(input, onComplete);
259+
}
260+
261+
/// <summary>
262+
/// Request password reset email for the user.
263+
///
264+
/// White label platform must be enabled in the web console for this to work.
265+
/// </summary>
266+
public static void WhiteLabelRequestPassword(string email, Action<LootLockerResponse> onComplete)
267+
{
268+
if (!CheckInitialized())
269+
{
270+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>());
271+
return;
272+
}
273+
274+
LootLockerAPIManager.WhiteLabelRequestPasswordReset(email, onComplete);
275+
}
276+
277+
/// <summary>
278+
/// Request verify account email for the user.
279+
///
280+
/// White label platform must be enabled in the web console for this to work.
281+
/// Account verification must also be enabled.
282+
/// </summary>
283+
public static void WhiteLabelRequestVerification(int userID, Action<LootLockerResponse> onComplete)
284+
{
285+
if (!CheckInitialized())
286+
{
287+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>());
288+
return;
289+
}
290+
291+
LootLockerAPIManager.WhiteLabelRequestAccountVerification(userID, onComplete);
292+
}
293+
294+
#endregion
295+
216296
#region Player
217297
//Player calls
218298
public static void GetPlayerInfo(Action<LootLockerGetPlayerInfoResponse> onComplete)

Runtime/Game/Requests/LootLockerSessionRequest.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ public LootLockerSessionRequest()
2727
}
2828
}
2929

30+
[System.Serializable]
31+
public class LootLockerWhiteLabelSessionRequest : LootLockerGetRequest
32+
{
33+
public string game_key => LootLockerConfig.current.apiKey?.ToString();
34+
public string email { get; private set; }
35+
public string password { get; private set; }
36+
public string game_version => LootLockerConfig.current.game_version;
37+
public bool development_mode => LootLockerConfig.current.developmentMode;
38+
public LootLockerWhiteLabelSessionRequest(string email, string password)
39+
{
40+
this.email = email;
41+
this.password = password;
42+
}
43+
}
44+
3045
[System.Serializable]
3146
public class LootLockerSessionResponse : LootLockerResponse
3247
{
@@ -88,6 +103,31 @@ public static void Session(LootLockerGetRequest data, Action<LootLockerSessionRe
88103
}, false);
89104
}
90105

106+
public static void WhiteLabelSession(LootLockerGetRequest data, Action<LootLockerSessionResponse> onComplete)
107+
{
108+
EndPointClass endPoint = LootLockerEndPoints.whiteLabelLoginSessionRequest;
109+
110+
string json = "";
111+
if (data == null) return;
112+
else json = JsonConvert.SerializeObject(data);
113+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, json, (serverResponse) =>
114+
{
115+
LootLockerSessionResponse response = new LootLockerSessionResponse();
116+
if (string.IsNullOrEmpty(serverResponse.Error))
117+
{
118+
response = JsonConvert.DeserializeObject<LootLockerSessionResponse>(serverResponse.text);
119+
LootLockerConfig.current.UpdateToken(response.session_token, (data as LootLockerSessionRequest)?.player_identifier);
120+
}
121+
122+
//LootLockerSDKManager.DebugMessage(serverResponse.text, !string.IsNullOrEmpty(serverResponse.Error));
123+
response.text = serverResponse.text;
124+
response.success = serverResponse.success;
125+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
126+
onComplete?.Invoke(response);
127+
128+
}, false);
129+
}
130+
91131
public static void GuestSession(LootLockerGetRequest data, Action<LootLockerGuestSessionResponse> onComplete)
92132
{
93133
EndPointClass endPoint = LootLockerEndPoints.guestSessionRequest;

0 commit comments

Comments
 (0)