Skip to content

Commit c794020

Browse files
Erik Bylundkirre-bylund
authored andcommitted
Add support for connected accounts
1 parent 7e476fe commit c794020

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public class LootLockerEndPoints
2323
public static EndPointClass appleGameCenterSessionRequest = new EndPointClass("session/apple/game-center", LootLockerHTTPMethod.POST);
2424
public static EndPointClass googleSessionRequest = new EndPointClass("session/google", LootLockerHTTPMethod.POST);
2525

26+
// Connected Accounts
27+
[Header("Connected Accounts")]
28+
public static EndPointClass listConnectedAccounts = new EndPointClass("connected-accounts", LootLockerHTTPMethod.GET);
29+
public static EndPointClass disconnectAccount = new EndPointClass("connected-accounts/{0}", LootLockerHTTPMethod.DELETE);
30+
public static EndPointClass connectProviderToAccount = new EndPointClass("connected-accounts/{0}", LootLockerHTTPMethod.PUT);
31+
2632
// Remote Sessions
2733
[Header("Remote Sessions")]
2834
public static EndPointClass leaseRemoteSession = new EndPointClass("session/remote/lease", LootLockerHTTPMethod.POST);

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,105 @@ public static void ClearLocalSession()
802802
}
803803
#endregion
804804

805+
#region Connected Accounts
806+
/// <summary>
807+
/// List identity providers (like Apple, Google, etc.) that are connected to the currently logged in account
808+
/// </summary>
809+
/// <param name="onComplete">onComplete Action for handling the response</param>
810+
public static void ListConnectedAccounts(Action<LootLockerListConnectedAccountsResponse> onComplete)
811+
{
812+
if (!CheckInitialized())
813+
{
814+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerListConnectedAccountsResponse>());
815+
return;
816+
}
817+
818+
LootLockerServerRequest.CallAPI(LootLockerEndPoints.listConnectedAccounts.endPoint, LootLockerEndPoints.listConnectedAccounts.httpMethod, null, (response) => { LootLockerResponse.Deserialize(onComplete, response); });
819+
}
820+
821+
/// <summary>
822+
/// Disconnect account from the currently logged in account
823+
///
824+
/// Use this to disconnect an account (like a Google or Apple account) that can be used to start sessions for this LootLocker account so that it is no longer allowed to do that
825+
/// </summary>
826+
/// <param name="accountToDisconnect">What account to disconnect from this LootLocker Account</param>
827+
/// <param name="onComplete">onComplete Action for handling the response</param>
828+
public static void DisconnectAccount(LootLockerAccountProvider accountToDisconnect, Action<LootLockerResponse> onComplete)
829+
{
830+
if (!CheckInitialized())
831+
{
832+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>());
833+
return;
834+
}
835+
836+
string endpoint = string.Format(LootLockerEndPoints.disconnectAccount.endPoint, accountToDisconnect);
837+
838+
LootLockerServerRequest.CallAPI(endpoint, LootLockerEndPoints.disconnectAccount.httpMethod, null, (response) => { LootLockerResponse.Deserialize(onComplete, response); });
839+
}
840+
841+
/// <summary>
842+
/// Connect a Google Account to the currently logged in LootLocker account allowing that google account to start sessions for this player
843+
/// </summary>
844+
/// <param name="idToken">The Id Token from google sign in</param>
845+
/// <param name="onComplete">onComplete Action for handling the response</param>
846+
public static void ConnectGoogleAccount(string idToken, Action<LootLockerResponse> onComplete)
847+
{
848+
if (!CheckInitialized())
849+
{
850+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>());
851+
return;
852+
}
853+
854+
string endpoint = string.Format(LootLockerEndPoints.connectProviderToAccount.endPoint, "google");
855+
856+
string data = LootLockerJson.SerializeObject(new LootLockerConnectGoogleProviderToAccountRequest{id_token = idToken });
857+
858+
LootLockerServerRequest.CallAPI(endpoint, LootLockerEndPoints.disconnectAccount.httpMethod, data, (response) => { LootLockerResponse.Deserialize(onComplete, response); });
859+
}
860+
861+
/// <summary>
862+
/// Connect a Google Account (with a Google Platform specified) to the currently logged in LootLocker account allowing that google account to start sessions for this player
863+
/// </summary>
864+
/// <param name="idToken">The Id Token from google sign in</param>
865+
/// <param name="platform">Google OAuth2 ClientID platform</param>
866+
/// <param name="onComplete">onComplete Action for handling the response</param>
867+
public static void ConnectGoogleAccount(string idToken, GoogleAccountProviderPlatform platform, Action<LootLockerResponse> onComplete)
868+
{
869+
if (!CheckInitialized())
870+
{
871+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>());
872+
return;
873+
}
874+
875+
string endpoint = string.Format(LootLockerEndPoints.connectProviderToAccount.endPoint, "google");
876+
877+
string data = LootLockerJson.SerializeObject(new LootLockerConnectGoogleProviderToAccountWithPlatformRequest() { id_token = idToken, platform = platform });
878+
879+
LootLockerServerRequest.CallAPI(endpoint, LootLockerEndPoints.disconnectAccount.httpMethod, data, (response) => { LootLockerResponse.Deserialize(onComplete, response); });
880+
}
881+
882+
/// <summary>
883+
/// Connect an Apple Account (authorized by Rest Sign In) to the currently logged in LootLocker account allowing that google account to start sessions for this player
884+
/// </summary>
885+
/// <param name="authorizationCode">Authorization code, provided by apple during Sign In</param>
886+
/// <param name="onComplete">onComplete Action for handling the response</param>
887+
public static void ConnectAppleAccountByRestSignIn(string authorizationCode, Action<LootLockerResponse> onComplete)
888+
{
889+
if (!CheckInitialized())
890+
{
891+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>());
892+
return;
893+
}
894+
895+
string endpoint = string.Format(LootLockerEndPoints.connectProviderToAccount.endPoint, "apple-rest");
896+
897+
string data = LootLockerJson.SerializeObject(new LootLockerConnectAppleRestProviderToAccountRequest() { authorization_code = authorizationCode });
898+
899+
LootLockerServerRequest.CallAPI(endpoint, LootLockerEndPoints.disconnectAccount.httpMethod, data, (response) => { LootLockerResponse.Deserialize(onComplete, response); });
900+
}
901+
902+
#endregion
903+
805904
#region Remote Sessions
806905

807906
/// <summary>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using LootLocker.LootLockerEnums;
2+
3+
namespace LootLocker.LootLockerEnums
4+
{
5+
/// <summary>
6+
/// TODO: Document
7+
/// </summary>
8+
public enum LootLockerAccountProvider
9+
{
10+
guest = 0,
11+
google = 1,
12+
apple = 2,
13+
}
14+
15+
/// <summary>
16+
/// TODO: Document
17+
/// </summary>
18+
public enum GoogleAccountProviderPlatform
19+
{
20+
web, android, ios, desktop
21+
}
22+
}
23+
24+
namespace LootLocker.Requests
25+
{
26+
//==================================================
27+
// Data Definitions
28+
//==================================================
29+
30+
/// <summary>
31+
/// </summary>
32+
public class LootLockerConnectedAccountProvider
33+
{
34+
/// <summary>
35+
/// TODO: Document
36+
/// </summary>
37+
public LootLockerAccountProvider provider { get; set; }
38+
/// <summary>
39+
/// TODO: Document
40+
/// </summary>
41+
public string provider_name { get; set; }
42+
}
43+
44+
//==================================================
45+
// Request Definitions
46+
//==================================================
47+
48+
/// <summary>
49+
/// </summary>
50+
public class LootLockerConnectGoogleProviderToAccountRequest
51+
{
52+
/// <summary>
53+
/// The Id Token from google sign in
54+
/// </summary>
55+
public string id_token { get; set; }
56+
}
57+
58+
/// <summary>
59+
/// </summary>
60+
public class LootLockerConnectGoogleProviderToAccountWithPlatformRequest
61+
{
62+
/// <summary>
63+
/// The Id Token from google sign in
64+
/// </summary>
65+
public string id_token { get; set; }
66+
/// <summary>
67+
/// Google OAuth2 ClientID platform
68+
/// </summary>
69+
public GoogleAccountProviderPlatform platform { get; set; }
70+
}
71+
72+
/// <summary>
73+
/// </summary>
74+
public class LootLockerConnectAppleRestProviderToAccountRequest
75+
{
76+
/// <summary>
77+
/// Authorization code, provided by apple during Sign In
78+
/// </summary>
79+
public string authorization_code { get; set; }
80+
}
81+
82+
//==================================================
83+
// Response Definitions
84+
//==================================================
85+
86+
/// <summary>
87+
/// </summary>
88+
public class LootLockerAccountConnectedResponse : LootLockerResponse
89+
{
90+
/// <summary>
91+
/// The account provider
92+
/// </summary>
93+
public LootLockerAccountProvider provider { get; set; }
94+
/// <summary>
95+
/// Decorated name of this provider to use for displaying
96+
/// </summary>
97+
public string provider_name { get; set; }
98+
}
99+
100+
/// <summary>
101+
/// </summary>
102+
public class LootLockerListConnectedAccountsResponse : LootLockerResponse
103+
{
104+
/// <summary>
105+
/// List of the accounts connected (allowed to start sessions for) to this LootLocker account
106+
/// </summary>
107+
public LootLockerConnectedAccountProvider[] connected_accounts { get; set; }
108+
}
109+
110+
111+
}

Runtime/Game/Requests/ConnectedAccountRequest.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)