Skip to content

Commit ab22f03

Browse files
committed
Add support for Epic sign in
1 parent 364c52a commit ab22f03

File tree

4 files changed

+139
-1
lines changed

4 files changed

+139
-1
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class LootLockerEndPoints
1616
public static EndPointClass twoFactorAuthenticationCodeVerification = new EndPointClass("v1/2fa", LootLockerHTTPMethod.POST);
1717
public static EndPointClass subsequentRequests = new EndPointClass("v1/games", LootLockerHTTPMethod.GET);
1818
public static EndPointClass nintendoSwitchSessionRequest = new EndPointClass("session/nintendo-switch", LootLockerHTTPMethod.POST);
19+
public static EndPointClass epicSessionRequest = new EndPointClass("session/epic", LootLockerHTTPMethod.POST);
1920
public static EndPointClass xboxSessionRequest = new EndPointClass("session/xbox-one", LootLockerHTTPMethod.POST);
2021
public static EndPointClass appleSessionRequest = new EndPointClass("session/apple", LootLockerHTTPMethod.POST);
2122
public static EndPointClass googleSessionRequest = new EndPointClass("session/google", LootLockerHTTPMethod.POST);

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,70 @@ public static void RefreshAppleSession(string refresh_token, Action<LootLockerAp
582582
});
583583
}
584584

585+
/// <summary>
586+
/// Create a new session for an Epic Online Services (EOS) user
587+
/// The Epic Games platform must be enabled in the web console for this to work.
588+
/// </summary>
589+
/// <param name="id_token">ESO Id Token as a string</param>
590+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerEpicSessionResponse</param>
591+
public static void StartEpicSession(string id_token, Action<LootLockerEpicSessionResponse> onComplete)
592+
{
593+
if (!CheckInitialized(true))
594+
{
595+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerEpicSessionResponse>());
596+
return;
597+
}
598+
CurrentPlatform.Set(Platforms.Epic);
599+
LootLockerEpicSessionRequest sessionRequest = new LootLockerEpicSessionRequest(id_token);
600+
LootLockerAPIManager.EpicSession(sessionRequest, response =>
601+
{
602+
if (!response.success)
603+
{
604+
CurrentPlatform.Reset();
605+
}
606+
onComplete(response);
607+
});
608+
}
609+
610+
/// <summary>
611+
/// Refresh a previous session signed in with Epic
612+
/// A response code of 401 (Unauthorized) means the refresh token has expired and you'll need to sign in again
613+
/// The Epic sign in platform must be enabled in the web console for this to work.
614+
/// </summary>
615+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerEpicSessionResponse</param>
616+
public static void RefreshEpicSession(Action<LootLockerEpicSessionResponse> onComplete)
617+
{
618+
RefreshEpicSession("", onComplete);
619+
}
620+
621+
/// <summary>
622+
/// Refresh a previous session signed in with Epic
623+
/// If you do not want to manually handle the refresh token we recommend using the RefreshEpicSession(Action<LootLockerEpicSessionResponse> onComplete) method.
624+
/// A response code of 401 (Unauthorized) means the refresh token has expired and you'll need to sign in again
625+
/// The Epic sign in platform must be enabled in the web console for this to work.
626+
/// </summary>
627+
/// <param name="refresh_token">Token received in response from StartEpicSession request</param>
628+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerEpicSessionResponse</param>
629+
public static void RefreshEpicSession(string refresh_token, Action<LootLockerEpicSessionResponse> onComplete)
630+
{
631+
if (!CheckInitialized(true))
632+
{
633+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerEpicSessionResponse>());
634+
return;
635+
}
636+
637+
CurrentPlatform.Set(Platforms.Epic);
638+
LootLockerEpicRefreshSessionRequest sessionRequest = new LootLockerEpicRefreshSessionRequest(string.IsNullOrEmpty(refresh_token) ? LootLockerConfig.current.refreshToken : refresh_token);
639+
LootLockerAPIManager.EpicSession(sessionRequest, response =>
640+
{
641+
if (!response.success)
642+
{
643+
CurrentPlatform.Reset();
644+
}
645+
onComplete(response);
646+
});
647+
}
648+
585649
/// <summary>
586650
/// End active session (if any exists)
587651
/// Succeeds if a session was ended or no sessions were active

Runtime/Game/Platforms/PlatformManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public enum Platforms
1818
,AppleSignIn
1919
,Android
2020
,Google
21+
,Epic
2122
}
2223

2324
public class CurrentPlatform
@@ -47,6 +48,7 @@ static CurrentPlatform()
4748
,"apple_sign_in" // AppleSignIn
4849
,"android" // Android
4950
,"google" // Google
51+
,"epic" // Epic Online Services / Epic Games
5052
};
5153
private static readonly string[] PlatformFriendlyStrings = new[]
5254
{
@@ -61,6 +63,7 @@ static CurrentPlatform()
6163
,"Apple Sign In" // AppleSignIn
6264
,"Android" // Android
6365
,"Google" // Google
66+
,"Epic Online Services" // Epic Online Services / Epic Games
6467
};
6568

6669
public struct PlatformRepresentation

Runtime/Game/Requests/LootLockerSessionRequest.cs

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ public class LootLockerAppleSessionResponse : LootLockerSessionResponse
103103
public string refresh_token { get; set; }
104104
}
105105

106+
[System.Serializable]
107+
public class LootLockerEpicSessionResponse : LootLockerSessionResponse
108+
{
109+
public string refresh_token { get; set; }
110+
}
111+
106112
[System.Serializable]
107113
public class LootLockerLevel_Thresholds
108114
{
@@ -125,6 +131,32 @@ public LootLockerNintendoSwitchSessionRequest(string nsa_id_token)
125131
}
126132
}
127133

134+
[System.Serializable]
135+
public class LootLockerEpicSessionRequest : LootLockerGetRequest
136+
{
137+
public string game_key => LootLockerConfig.current.apiKey?.ToString();
138+
public string id_token { get; private set; }
139+
public string game_version => LootLockerConfig.current.game_version;
140+
141+
public LootLockerEpicSessionRequest(string id_token)
142+
{
143+
this.id_token = id_token;
144+
}
145+
}
146+
147+
[System.Serializable]
148+
public class LootLockerEpicRefreshSessionRequest : LootLockerGetRequest
149+
{
150+
public string game_key => LootLockerConfig.current.apiKey?.ToString();
151+
public string refresh_token { get; private set; }
152+
public string game_version => LootLockerConfig.current.game_version;
153+
154+
public LootLockerEpicRefreshSessionRequest(string refresh_token)
155+
{
156+
this.refresh_token = refresh_token;
157+
}
158+
}
159+
128160
public class LootLockerXboxOneSessionRequest : LootLockerGetRequest
129161
{
130162
public string game_key => LootLockerConfig.current.apiKey?.ToString();
@@ -310,13 +342,51 @@ public static void NintendoSwitchSession(LootLockerNintendoSwitchSessionRequest
310342
LootLockerConfig.AddDevelopmentModeFieldToJsonStringIfNeeded(ref json); // TODO: Deprecated, remove in version 1.2.0
311343
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, json, (serverResponse) =>
312344
{
313-
var response = LootLockerResponse.Deserialize<LootLockerGuestSessionResponse>(serverResponse);
345+
var response = LootLockerResponse.Deserialize<LootLockerSessionResponse>(serverResponse);
314346
LootLockerConfig.current.token = response.session_token;
315347
LootLockerConfig.current.deviceID = "";
316348
onComplete?.Invoke(response);
317349
}, false);
318350
}
319351

352+
public static void EpicSession(LootLockerEpicSessionRequest data, Action<LootLockerEpicSessionResponse> onComplete)
353+
{
354+
if (data == null)
355+
{
356+
onComplete?.Invoke(LootLockerResponseFactory.InputUnserializableError<LootLockerEpicSessionResponse>());
357+
return;
358+
}
359+
360+
string json = JsonConvert.SerializeObject(data);
361+
EpicSession(json, onComplete);
362+
}
363+
364+
public static void EpicSession(LootLockerEpicRefreshSessionRequest data, Action<LootLockerEpicSessionResponse> onComplete)
365+
{
366+
if (data == null)
367+
{
368+
onComplete?.Invoke(LootLockerResponseFactory.InputUnserializableError<LootLockerEpicSessionResponse>());
369+
return;
370+
}
371+
372+
string json = JsonConvert.SerializeObject(data);
373+
EpicSession(json, onComplete);
374+
}
375+
376+
private static void EpicSession(string json, Action<LootLockerEpicSessionResponse> onComplete)
377+
{
378+
EndPointClass endPoint = LootLockerEndPoints.epicSessionRequest;
379+
LootLockerConfig.AddDevelopmentModeFieldToJsonStringIfNeeded(ref json); // TODO: Deprecated, remove in version 1.2.0
380+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, json, (serverResponse) =>
381+
{
382+
var response = LootLockerResponse.Deserialize<LootLockerEpicSessionResponse>(serverResponse);
383+
LootLockerConfig.current.token = response.session_token;
384+
LootLockerConfig.current.refreshToken = response.refresh_token;
385+
LootLockerConfig.current.deviceID = "";
386+
onComplete?.Invoke(response);
387+
}, false);
388+
}
389+
320390
public static void XboxOneSession(LootLockerXboxOneSessionRequest data, Action<LootLockerSessionResponse> onComplete)
321391
{
322392
EndPointClass endPoint = LootLockerEndPoints.xboxSessionRequest;

0 commit comments

Comments
 (0)