Skip to content

Commit 1669e46

Browse files
kirre-bylundMikkel Sørensen
authored andcommitted
Add support for account linking
1 parent 47c26d5 commit 1669e46

File tree

5 files changed

+189
-2
lines changed

5 files changed

+189
-2
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ public class LootLockerEndPoints
3131
public static EndPointClass whiteLabelRequestAccountVerification = new EndPointClass("white-label-login/request-verification", LootLockerHTTPMethod.POST);
3232
public static EndPointClass whiteLabelLoginSessionRequest = new EndPointClass("v2/session/white-label", LootLockerHTTPMethod.POST);
3333

34+
// Account Linking
35+
[Header("Account Linking")]
36+
public static EndPointClass StartAccountLinkingProcess = new EndPointClass("upa/link/start", LootLockerHTTPMethod.POST);
37+
public static EndPointClass CheckStatusOfAccountLinkingProcess = new EndPointClass("upa/link/{0}", LootLockerHTTPMethod.GET);
38+
public static EndPointClass CancelAccountLinkingProcess = new EndPointClass("upa/link/{0}", LootLockerHTTPMethod.DELETE);
39+
public static EndPointClass UnlinkProviderFromAccount = new EndPointClass("player/providers/{0}", LootLockerHTTPMethod.DELETE);
40+
3441
// Player
3542
[Header("Player")]
3643
public static EndPointClass getPlayerInfo = new EndPointClass("v1/player/info", LootLockerHTTPMethod.GET);

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
using static LootLocker.LootLockerConfig;
99
using System.Linq;
1010
using static LootLocker.Requests.CurrentPlatform;
11+
using static System.Net.WebRequestMethods;
12+
using static System.Runtime.CompilerServices.RuntimeHelpers;
13+
using System.Diagnostics;
14+
using File = System.IO.File;
1115
#if UNITY_EDITOR
1216
using UnityEditor;
1317
#endif
@@ -1061,6 +1065,90 @@ public static void WhiteLabelLoginAndStartSession(string email, string password,
10611065

10621066
#endregion
10631067

1068+
#region Account Linking
1069+
1070+
/// <summary>
1071+
/// Start an account linking process on behalf of the currently signed in player
1072+
/// When you want to link an additional provider to a player, you start by initiating an account link.The player can then navigate to the online link flow using the code_page_url and code, or the qr_code and continue the linking process.
1073+
/// For the duration of the linking process you can check the status using the CheckStatusOfAccountLinkingProcess method.
1074+
/// Returned from this method is the ID of the linking process, make sure to save that so that you can check the status of the process later.
1075+
/// https://ref.lootlocker.com/game-api/#start-account-link
1076+
/// </summary>
1077+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerAccountLinkStartResponse</param>
1078+
public static void StartAccountLinkingProcess(Action<LootLockerAccountLinkStartResponse> onComplete)
1079+
{
1080+
if (!CheckInitialized())
1081+
{
1082+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerAccountLinkStartResponse>());
1083+
return;
1084+
}
1085+
1086+
var endpoint = LootLockerEndPoints.StartAccountLinkingProcess;
1087+
1088+
LootLockerServerRequest.CallAPI(endpoint.endPoint, endpoint.httpMethod, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
1089+
}
1090+
1091+
/// <summary>
1092+
/// Check the status of an ongoing account linking process
1093+
/// https://ref.lootlocker.com/game-api/#check-account-link-status
1094+
/// </summary>
1095+
/// <param name="LinkID">The ID of the account linking process which was returned when starting the linking process</param>
1096+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerAccountLinkProcessStatusResponse</param>
1097+
public static void CheckStatusOfAccountLinkingProcess(string LinkID, Action<LootLockerAccountLinkProcessStatusResponse> onComplete)
1098+
{
1099+
if (!CheckInitialized())
1100+
{
1101+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerAccountLinkProcessStatusResponse>());
1102+
return;
1103+
}
1104+
1105+
var endpoint = LootLockerEndPoints.CheckStatusOfAccountLinkingProcess;
1106+
1107+
LootLockerServerRequest.CallAPI(string.Format(endpoint.endPoint, LinkID), endpoint.httpMethod, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
1108+
}
1109+
1110+
/// <summary>
1111+
/// Cancel an ongoing account linking process
1112+
/// The response will be empty unless an error occurs
1113+
/// https://ref.lootlocker.com/game-api/#cancel-account-link
1114+
/// </summary>
1115+
/// <param name="LinkID">The ID of the account linking process which was returned when starting the linking process</param>
1116+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerCancelAccountLinkingProcessResponse</param>
1117+
public static void CancelAccountLinkingProcess(string LinkID, Action<LootLockerCancelAccountLinkingProcessResponse> onComplete)
1118+
{
1119+
if (!CheckInitialized())
1120+
{
1121+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerCancelAccountLinkingProcessResponse>());
1122+
return;
1123+
}
1124+
1125+
var endpoint = LootLockerEndPoints.CancelAccountLinkingProcess;
1126+
1127+
LootLockerServerRequest.CallAPI(string.Format(endpoint.endPoint, LinkID), endpoint.httpMethod, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
1128+
}
1129+
1130+
/// <summary>
1131+
/// Unlink a provider from the currently signed in player
1132+
/// The response will be empty unless an error occurs
1133+
/// https://ref.lootlocker.com/game-api/#unlink-provider
1134+
/// </summary>
1135+
/// <param name="Provider">What provider to unlink from the currently logged in player</param>
1136+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerUnlinkProviderFromAccountResponse</param>
1137+
public static void UnlinkProviderFromAccount(Platforms Provider, Action<LootLockerUnlinkProviderFromAccountResponse> onComplete)
1138+
{
1139+
if (!CheckInitialized())
1140+
{
1141+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerUnlinkProviderFromAccountResponse>());
1142+
return;
1143+
}
1144+
1145+
var endpoint = LootLockerEndPoints.UnlinkProviderFromAccount;
1146+
1147+
LootLockerServerRequest.CallAPI(string.Format(endpoint.endPoint, CurrentPlatform.GetPlatformRepresentation(Provider).PlatformString), endpoint.httpMethod, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
1148+
}
1149+
1150+
#endregion
1151+
10641152
#region Player
10651153
/// <summary>
10661154
/// Get general information about the current current player, such as the XP, Level information and their account balance.

Runtime/Game/Platforms/PlatformManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ static CurrentPlatform()
4949
,"apple_sign_in" // AppleSignIn
5050
,"apple_game_center" // Apple Game Center
5151
,"android" // Android
52-
,"google" // Google
53-
,"epic" // Epic Online Services / Epic Games
52+
,"google_sign_in" // Google
53+
,"epic_games" // Epic Online Services / Epic Games
5454
};
5555
private static readonly string[] PlatformFriendlyStrings = new[]
5656
{
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using LootLocker.LootLockerEnums;
2+
using LootLocker.Requests;
3+
using System;
4+
using System.Collections.Generic;
5+
using static UnityEngine.UI.CanvasScaler;
6+
7+
namespace LootLocker.LootLockerEnums
8+
{
9+
/*
10+
* Possible account linking process statuses. Undefined means that the object couldn't be constructed correctly
11+
*/
12+
public enum LootLockerAccountLinkingProcessStatus
13+
{
14+
Undefined = 0,
15+
Started = 1,
16+
Cancelled = 2,
17+
Completed = 3
18+
};
19+
}
20+
21+
22+
namespace LootLocker.Requests
23+
{
24+
//==================================================
25+
// Response Definitions
26+
//==================================================
27+
28+
/*
29+
*
30+
*/
31+
public class LootLockerAccountLinkStartResponse : LootLockerResponse
32+
{
33+
/*
34+
* ID of the account linking process. Save this as you will need it for checking the linking process status and if you want to cancel it.
35+
*/
36+
public string Link_id { get; set; }
37+
/*
38+
* Used by the user in the online account linking process
39+
*/
40+
public string Code { get; set; }
41+
/*
42+
* Base64 encoded PNG image of a qr code that can be shown to the player for them to scan and open the account linking flow
43+
*/
44+
public string Qr_code { get; set; }
45+
/*
46+
* URL to where the user can continue the online account linking process
47+
*/
48+
public string Code_page_url { get; set; }
49+
};
50+
51+
/*
52+
*
53+
*/
54+
public class LootLockerAccountLinkProcessStatusResponse : LootLockerResponse
55+
{
56+
/*
57+
* Current status of the specified account linking process
58+
*/
59+
60+
LootLockerAccountLinkingProcessStatus Status = LootLockerAccountLinkingProcessStatus.Undefined;
61+
/*
62+
* Time when the specified account linking process was started
63+
*/
64+
public string Created_at { get; set; }
65+
};
66+
67+
/*
68+
* This response will be empty unless there's an error
69+
*/
70+
public class LootLockerCancelAccountLinkingProcessResponse : LootLockerResponse
71+
{
72+
};
73+
74+
/*
75+
* This response will be empty unless there's an error
76+
*/
77+
public class LootLockerUnlinkProviderFromAccountResponse : LootLockerResponse
78+
{
79+
};
80+
81+
}

Runtime/Game/Requests/AccountLinkRequest.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)