Skip to content

Commit e6fc475

Browse files
committed
Add support for new white label login calls
1 parent 5cc9976 commit e6fc475

File tree

4 files changed

+257
-15
lines changed

4 files changed

+257
-15
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class LootLockerEndPoints
2121
// White Label Login
2222
[Header("White Label Login")]
2323
public static EndPointClass whiteLabelSignUp = new EndPointClass("white-label-login/sign-up", LootLockerHTTPMethod.POST);
24+
public static EndPointClass whiteLabelLogin = new EndPointClass("white-label-login/login", LootLockerHTTPMethod.POST);
25+
public static EndPointClass whiteLabelVerifySession = new EndPointClass("white-label-login/verify-session", LootLockerHTTPMethod.POST);
2426
public static EndPointClass whiteLabelRequestPasswordReset = new EndPointClass("white-label-login/request-reset-password", LootLockerHTTPMethod.POST);
2527
public static EndPointClass whiteLabelRequestAccountVerification = new EndPointClass("white-label-login/request-verification", LootLockerHTTPMethod.POST);
2628

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,79 @@ public static void StartSteamSession(string steamId64, Action<LootLockerSessionR
190190
LootLockerAPIManager.Session(sessionRequest, onComplete);
191191
}
192192

193+
/// <summary>
194+
/// Checks if we have a stored session and also if that session is valid.
195+
///
196+
/// Depending on response of this method the developer can either start a session using the token,
197+
/// or show a login form.
198+
///
199+
/// White label platform must be enabled in the web console for this to work.
200+
/// </summary>
201+
public static void CheckWhiteLabelSession(Action<bool> onComplete)
202+
{
203+
if (!CheckInitialized())
204+
{
205+
onComplete(false);
206+
return;
207+
}
208+
209+
//PlayerPrefs.SetString("LootLockerWhiteLabelSessionToken", response.player_identifier);
210+
//PlayerPrefs.Save();
211+
212+
string existingSessionToken = PlayerPrefs.GetString("LootLockerWhiteLabelSessionToken", "");
213+
if (existingSessionToken == "")
214+
{
215+
onComplete(false);
216+
return;
217+
}
218+
219+
string existingSessionEmail = PlayerPrefs.GetString("LootLockerWhiteLabelSessionEmail", "");
220+
if (existingSessionEmail == "")
221+
{
222+
onComplete(false);
223+
return;
224+
}
225+
226+
LootLockerWhiteLabelVerifySessionRequest sessionRequest = new LootLockerWhiteLabelVerifySessionRequest();
227+
sessionRequest.email = existingSessionEmail;
228+
sessionRequest.token = existingSessionToken;
229+
230+
LootLockerAPIManager.WhiteLabelVerifySession(sessionRequest, response =>
231+
{
232+
if (!response.success)
233+
{
234+
onComplete(false);
235+
return;
236+
}
237+
238+
onComplete(true);
239+
});
240+
}
241+
242+
public static void CheckWhiteLabelSession(string email, string token, Action<bool> onComplete)
243+
{
244+
if (!CheckInitialized())
245+
{
246+
onComplete(false);
247+
return;
248+
}
249+
250+
LootLockerWhiteLabelVerifySessionRequest sessionRequest = new LootLockerWhiteLabelVerifySessionRequest();
251+
sessionRequest.email = email;
252+
sessionRequest.token = token;
253+
254+
LootLockerAPIManager.WhiteLabelVerifySession(sessionRequest, response =>
255+
{
256+
if (!response.success)
257+
{
258+
onComplete(false);
259+
return;
260+
}
261+
262+
onComplete(true);
263+
});
264+
}
265+
193266
/// <summary>
194267
/// Create new user using the white label login system.
195268
///
@@ -218,10 +291,22 @@ public static void StartNintendoSwitchSession(string nsa_id_token, Action<LootLo
218291
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerSessionResponse>());
219292
return;
220293
}
221-
LootLockerNintendoSwitchSessionRequest sessionRequest = new LootLockerNintendoSwitchSessionRequest(nsa_id_token);
294+
LootLockerAPIManager.LootLockerNintendoSwitchSessionRequest sessionRequest = new LootLockerAPIManager.LootLockerNintendoSwitchSessionRequest(nsa_id_token);
222295
LootLockerAPIManager.NintendoSwitchSession(sessionRequest, onComplete);
223296
}
224297

298+
public static void StartWhiteLabelSession(LootLockerWhiteLabelSessionRequest input, Action<LootLockerSessionResponse> onComplete)
299+
{
300+
if (!CheckInitialized())
301+
{
302+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerSessionResponse>());
303+
return;
304+
}
305+
LootLockerWhiteLabelSessionRequest sessionRequest = new LootLockerWhiteLabelSessionRequest(input.email);
306+
sessionRequest.token = input.token;
307+
LootLockerAPIManager.WhiteLabelSession(sessionRequest, onComplete);
308+
}
309+
225310
public static void EndSession(string deviceId, Action<LootLockerSessionResponse> onComplete)
226311
{
227312
if (!CheckInitialized())
@@ -246,6 +331,46 @@ public static void EndSession(string deviceId, Action<LootLockerSessionResponse>
246331
///
247332
/// White label platform must be enabled in the web console for this to work.
248333
/// </summary>
334+
public static void WhiteLabelLogin(string email, string password, Action<LootLockerWhiteLabelLoginResponse> onComplete)
335+
{
336+
if (!CheckInitialized())
337+
{
338+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerWhiteLabelLoginResponse>());
339+
return;
340+
}
341+
342+
LootLockerWhiteLabelUserRequest input = new LootLockerWhiteLabelUserRequest
343+
{
344+
email = email,
345+
password = password
346+
};
347+
348+
LootLockerAPIManager.WhiteLabelLogin(input, onComplete);
349+
}
350+
351+
public static void WhiteLabelLogin(string email, string password, bool remember, Action<LootLockerWhiteLabelLoginResponse> onComplete)
352+
{
353+
if (!CheckInitialized())
354+
{
355+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerWhiteLabelLoginResponse>());
356+
return;
357+
}
358+
359+
LootLockerWhiteLabelUserRequest input = new LootLockerWhiteLabelUserRequest
360+
{
361+
email = email,
362+
password = password,
363+
remember = remember
364+
};
365+
366+
LootLockerAPIManager.WhiteLabelLogin(input, onComplete);
367+
}
368+
369+
/// <summary>
370+
/// Create new user using the white label login system.
371+
///
372+
/// White label platform must be enabled in the web console for this to work.
373+
/// </summary>
249374
public static void WhiteLabelSignUp(string email, string password, Action<LootLockerWhiteLabelSignupResponse> onComplete)
250375
{
251376
if (!CheckInitialized())

Runtime/Game/Requests/LootLockerSessionRequest.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,25 @@ public class LootLockerWhiteLabelSessionRequest : LootLockerGetRequest
3333
public string game_key => LootLockerConfig.current.apiKey?.ToString();
3434
public string email { get; private set; }
3535
public string password { get; private set; }
36+
public string token { get; set; }
3637
public string game_version => LootLockerConfig.current.game_version;
3738
public bool development_mode => LootLockerConfig.current.developmentMode;
3839
public LootLockerWhiteLabelSessionRequest(string email, string password)
3940
{
4041
this.email = email;
4142
this.password = password;
4243
}
43-
}
4444

45-
[System.Serializable]
46-
public class LootLockerNintendoSwitchSessionRequest : LootLockerGetRequest
47-
{
48-
public string game_key => LootLockerConfig.current.apiKey?.ToString();
49-
public string nsa_id_token { get; private set; }
50-
public string game_version => LootLockerConfig.current.game_version;
51-
public bool development_mode => LootLockerConfig.current.developmentMode;
52-
public LootLockerNintendoSwitchSessionRequest(string nsa_id_token)
45+
public LootLockerWhiteLabelSessionRequest(string email)
5346
{
54-
this.nsa_id_token = nsa_id_token;
47+
this.email = email;
5548
}
5649
}
5750

5851
[System.Serializable]
5952
public class LootLockerSessionResponse : LootLockerResponse
6053
{
61-
54+
6255
public string session_token { get; set; }
6356
public int player_id { get; set; }
6457
public bool seen_before { get; set; }
@@ -116,7 +109,20 @@ public static void Session(LootLockerGetRequest data, Action<LootLockerSessionRe
116109
}, false);
117110
}
118111

119-
public static void WhiteLabelSession(LootLockerWhiteLabelSessionRequest data, Action<LootLockerSessionResponse> onComplete)
112+
[System.Serializable]
113+
public class LootLockerNintendoSwitchSessionRequest : LootLockerGetRequest
114+
{
115+
public string game_key => LootLockerConfig.current.apiKey?.ToString();
116+
public string nsa_id_token { get; private set; }
117+
public string game_version => LootLockerConfig.current.game_version;
118+
public bool development_mode => LootLockerConfig.current.developmentMode;
119+
public LootLockerNintendoSwitchSessionRequest(string nsa_id_token)
120+
{
121+
this.nsa_id_token = nsa_id_token;
122+
}
123+
}
124+
125+
public static void WhiteLabelSession(LootLockerGetRequest data, Action<LootLockerSessionResponse> onComplete)
120126
{
121127
EndPointClass endPoint = LootLockerEndPoints.whiteLabelLoginSessionRequest;
122128

@@ -185,7 +191,7 @@ public static void NintendoSwitchSession(LootLockerNintendoSwitchSessionRequest
185191
if (string.IsNullOrEmpty(serverResponse.Error))
186192
{
187193
response = JsonConvert.DeserializeObject<LootLockerSessionResponse>(serverResponse.text);
188-
LootLockerConfig.current.UpdateToken(response.session_token, (data as LootLockerSessionRequest)?.player_identifier);
194+
LootLockerConfig.current.UpdateToken(response.session_token, "");
189195
}
190196

191197
response.text = serverResponse.text;
@@ -208,7 +214,7 @@ public static void EndSession(LootLockerGetRequest data, Action<LootLockerSessio
208214
LootLockerSessionResponse response = new LootLockerSessionResponse();
209215
if (string.IsNullOrEmpty(serverResponse.Error))
210216
response = JsonConvert.DeserializeObject<LootLockerSessionResponse>(serverResponse.text);
211-
217+
212218
//LootLockerSDKManager.DebugMessage(serverResponse.text, !string.IsNullOrEmpty(serverResponse.Error));
213219
response.text = serverResponse.text;
214220
response.success = serverResponse.success;

Runtime/Game/Requests/WhiteLabelRequest.cs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ public class LootLockerWhiteLabelUserRequest
1414
{
1515
public string email { get; set; }
1616
public string password { get; set; }
17+
public bool remember { get; set; }
18+
}
19+
20+
public class LootLockerWhiteLabelVerifySessionRequest
21+
{
22+
public string email { get; set; }
23+
public string token { get; set; }
24+
}
25+
26+
public class LootLockerWhiteLabelVerifySessionResponse : LootLockerResponse
27+
{
28+
public string Email { get; set; }
29+
public string Token { get; set; }
1730
}
1831

1932
public class LootLockerWhiteLabelSignupResponse : LootLockerResponse
@@ -29,12 +42,108 @@ public class LootLockerWhiteLabelSignupResponse : LootLockerResponse
2942
#nullable enable
3043
public string? ValidatedAt { get; set; }
3144
}
45+
46+
public class LootLockerWhiteLabelLoginResponse : LootLockerWhiteLabelSignupResponse
47+
{
48+
public string? SessionToken { get; set; }
49+
}
3250
}
3351

3452
namespace LootLocker
3553
{
3654
public partial class LootLockerAPIManager
3755
{
56+
57+
public static void WhiteLabelLogin(LootLockerWhiteLabelUserRequest input, Action<LootLockerWhiteLabelLoginResponse> onComplete)
58+
{
59+
EndPointClass endPoint = LootLockerEndPoints.whiteLabelLogin;
60+
61+
string json = "";
62+
if (input == null)
63+
{
64+
return;
65+
}
66+
else
67+
{
68+
json = JsonConvert.SerializeObject(input);
69+
}
70+
71+
LootLockerServerRequest.CallDomainAuthAPI(endPoint.endPoint, endPoint.httpMethod, json, ((serverResponse) =>
72+
{
73+
LootLockerWhiteLabelLoginResponse? response = new LootLockerWhiteLabelLoginResponse();
74+
if (string.IsNullOrEmpty(serverResponse.Error) && serverResponse.text != null)
75+
{
76+
DefaultContractResolver contractResolver = new DefaultContractResolver
77+
{
78+
NamingStrategy = new SnakeCaseNamingStrategy()
79+
};
80+
81+
response = JsonConvert.DeserializeObject<LootLockerWhiteLabelLoginResponse>(serverResponse.text, new JsonSerializerSettings
82+
{
83+
ContractResolver = contractResolver,
84+
Formatting = Formatting.Indented
85+
});
86+
87+
if (response == null)
88+
{
89+
response = LootLockerResponseFactory.Error<LootLockerWhiteLabelLoginResponse>("error deserializing server response");
90+
onComplete?.Invoke(response);
91+
return;
92+
}
93+
}
94+
95+
response.text = serverResponse.text;
96+
response.success = serverResponse.success;
97+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
98+
onComplete?.Invoke(response);
99+
}));
100+
}
101+
102+
public static void WhiteLabelVerifySession(LootLockerWhiteLabelVerifySessionRequest input, Action<LootLockerWhiteLabelVerifySessionResponse> onComplete)
103+
{
104+
EndPointClass endPoint = LootLockerEndPoints.whiteLabelVerifySession;
105+
106+
string json = "";
107+
if (input == null)
108+
{
109+
return;
110+
}
111+
else
112+
{
113+
json = JsonConvert.SerializeObject(input);
114+
}
115+
116+
LootLockerServerRequest.CallDomainAuthAPI(endPoint.endPoint, endPoint.httpMethod, json, ((serverResponse) =>
117+
{
118+
LootLockerWhiteLabelVerifySessionResponse? response = new LootLockerWhiteLabelVerifySessionResponse();
119+
if (string.IsNullOrEmpty(serverResponse.Error) && serverResponse.text != null)
120+
{
121+
DefaultContractResolver contractResolver = new DefaultContractResolver
122+
{
123+
NamingStrategy = new SnakeCaseNamingStrategy()
124+
};
125+
126+
response = JsonConvert.DeserializeObject<LootLockerWhiteLabelVerifySessionResponse>(serverResponse.text, new JsonSerializerSettings
127+
{
128+
ContractResolver = contractResolver,
129+
Formatting = Formatting.Indented
130+
});
131+
132+
if (response == null)
133+
{
134+
response = LootLockerResponseFactory.Error<LootLockerWhiteLabelVerifySessionResponse>("error deserializing server response");
135+
onComplete?.Invoke(response);
136+
return;
137+
}
138+
}
139+
140+
response.text = serverResponse.text;
141+
response.success = serverResponse.success;
142+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
143+
onComplete?.Invoke(response);
144+
}));
145+
}
146+
38147
public static void WhiteLabelSignUp(LootLockerWhiteLabelUserRequest input, Action<LootLockerWhiteLabelSignupResponse> onComplete)
39148
{
40149
EndPointClass endPoint = LootLockerEndPoints.whiteLabelSignUp;

0 commit comments

Comments
 (0)