Skip to content

Commit e6e12fc

Browse files
committed
Add support for Apple sign in
1 parent 07a3da4 commit e6e12fc

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class LootLockerEndPoints
1818
public static EndPointClass subsequentRequests = new EndPointClass("v1/games", LootLockerHTTPMethod.GET);
1919
public static EndPointClass nintendoSwitchSessionRequest = new EndPointClass("session/nintendo-switch", LootLockerHTTPMethod.POST);
2020
public static EndPointClass xboxSessionRequest = new EndPointClass("session/xbox-one", LootLockerHTTPMethod.POST);
21+
public static EndPointClass appleSessionRequest = new EndPointClass("session/apple", LootLockerHTTPMethod.POST);
2122

2223
// White Label Login
2324
[Header("White Label Login")]

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,22 @@ public static void StartXboxOneSession(string xbox_user_token, Action<LootLocker
373373
LootLockerAPIManager.XboxOneSession(sessionRequest, onComplete);
374374
}
375375

376+
/// <summary>
377+
/// Create a new session for Sing in with Apple
378+
///
379+
/// The Apple sign in platform must be enabled in the web console for this to work.
380+
/// </summary>
381+
public static void StartAppleSession(string token, Action<LootLockerSessionResponse> onComplete)
382+
{
383+
if (!CheckInitialized())
384+
{
385+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerSessionResponse>());
386+
return;
387+
}
388+
LootLockerAppleSignInSessionRequest sessionRequest = new LootLockerAppleSignInSessionRequest(token);
389+
LootLockerAPIManager.AppleSession(sessionRequest, onComplete);
390+
}
391+
376392
public static void EndSession(string deviceId, Action<LootLockerSessionResponse> onComplete)
377393
{
378394
if (!CheckInitialized())

Runtime/Game/Requests/LootLockerSessionRequest.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ public LootLockerXboxOneSessionRequest(string xbox_user_token)
102102
this.xbox_user_token = xbox_user_token;
103103
}
104104
}
105+
106+
public class LootLockerAppleSignInSessionRequest : LootLockerGetRequest
107+
{
108+
public string game_key => LootLockerConfig.current.apiKey?.ToString();
109+
public string apple_user_token { get; private set; }
110+
public string game_version => LootLockerConfig.current.game_version;
111+
public bool development_mode => LootLockerConfig.current.developmentMode;
112+
public LootLockerAppleSignInSessionRequest(string apple_user_token)
113+
{
114+
this.apple_user_token = apple_user_token;
115+
}
116+
}
105117
}
106118

107119
namespace LootLocker
@@ -241,6 +253,34 @@ public static void XboxOneSession(LootLockerXboxOneSessionRequest data, Action<L
241253
}, false);
242254
}
243255

256+
public static void AppleSession(LootLockerAppleSignInSessionRequest data, Action<LootLockerSessionResponse> onComplete)
257+
{
258+
EndPointClass endPoint = LootLockerEndPoints.appleSessionRequest;
259+
260+
string json = "";
261+
if (data == null)
262+
{
263+
return;
264+
}
265+
266+
json = JsonConvert.SerializeObject(data);
267+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, json, (serverResponse) =>
268+
{
269+
LootLockerSessionResponse response = new LootLockerSessionResponse();
270+
if (string.IsNullOrEmpty(serverResponse.Error))
271+
{
272+
response = JsonConvert.DeserializeObject<LootLockerSessionResponse>(serverResponse.text);
273+
LootLockerConfig.current.UpdateToken(response.session_token, "");
274+
}
275+
276+
response.text = serverResponse.text;
277+
response.success = serverResponse.success;
278+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
279+
onComplete?.Invoke(response);
280+
281+
}, false);
282+
}
283+
244284
public static void EndSession(LootLockerGetRequest data, Action<LootLockerSessionResponse> onComplete)
245285
{
246286
EndPointClass endPoint = LootLockerEndPoints.endingSession;

0 commit comments

Comments
 (0)