Skip to content

Commit a8d8f09

Browse files
authored
Merge pull request #13 from LootLocker/refresh-token-fix
Fix for Token refresh
2 parents 695f56d + 873e019 commit a8d8f09

File tree

7 files changed

+281
-194
lines changed

7 files changed

+281
-194
lines changed

Runtime/Client/LootLockerBaseServerAPI.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,8 @@ IEnumerator coroutine()
156156
break;
157157
}
158158

159-
LootLockerSDKManager.DebugMessage("Response code: " + webRequest.responseCode);
160-
161-
162-
if ((webRequest.responseCode == 401 || webRequest.responseCode == 403) && LootLockerConfig.current.allowTokenRefresh && LootLockerConfig.current.platform != LootLockerConfig.platformType.Steam
163-
&& tries < maxRetry)
159+
bool isSteam = LootLockerSDKManager.GetCurrentPlatform() == "steam";
160+
if ((webRequest.responseCode == 401 || webRequest.responseCode == 403) && LootLockerConfig.current.allowTokenRefresh && !isSteam && tries < maxRetry)
164161
{
165162
tries++;
166163
LootLockerSDKManager.DebugMessage("Refreshing Token, Since we could not find one. If you do not want this please turn off in the lootlocker config settings");

Runtime/Game/LootLockerGameServerAPI.cs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
namespace LootLocker
99
{
10-
/// <summary>
11-
/// made for user, relay on playtime coroutines
12-
/// </summary>
1310
public class LootLockerGameServerAPI : LootLockerBaseServerAPI
1411
{
1512
public new static LootLockerGameServerAPI I;
@@ -28,9 +25,22 @@ public static void Init(LootLockerServerManager serverManager)
2825

2926
protected override void RefreshTokenAndCompleteCall(LootLockerServerRequest cacheServerRequest, Action<LootLockerResponse> OnServerResponse)
3027
{
31-
if (LootLockerConfig.current.platform == LootLockerConfig.platformType.Steam)
28+
string platform = LootLockerSDKManager.GetCurrentPlatform();
29+
30+
if (platform == Platforms.Steam)
31+
{
32+
LootLockerSDKManager.DebugMessage("Token has expired and token refresh is not supported for Steam", true);
33+
LootLockerResponse res = new LootLockerResponse();
34+
res.statusCode = 401;
35+
res.Error = "Token Expired";
36+
res.hasError = true;
37+
OnServerResponse?.Invoke(res);
38+
return;
39+
}
40+
41+
if (platform == Platforms.NintendoSwitch)
3242
{
33-
LootLockerSDKManager.DebugMessage("Token has expired, And token refresh not supported in Steam calls", true);
43+
LootLockerSDKManager.DebugMessage("Token has expired and token refresh is not supported for Nintendo Switch", true);
3444
LootLockerResponse res = new LootLockerResponse();
3545
res.statusCode = 401;
3646
res.Error = "Token Expired";
@@ -39,9 +49,30 @@ protected override void RefreshTokenAndCompleteCall(LootLockerServerRequest cach
3949
return;
4050
}
4151

42-
var sessionRequest = new LootLockerSessionRequest(LootLockerConfig.current.deviceID);
52+
if (platform == Platforms.Guest)
53+
{
54+
LootLockerSDKManager.StartGuestSession(response =>
55+
{
56+
CompleteCall(cacheServerRequest, OnServerResponse, response);
57+
});
58+
return;
59+
} else if (platform == Platforms.WhiteLabel)
60+
{
61+
LootLockerSDKManager.StartWhiteLabelSession(response =>
62+
{
63+
CompleteCall(cacheServerRequest, OnServerResponse, response);
64+
});
4365

44-
LootLockerAPIManager.Session(sessionRequest, (response) =>
66+
return;
67+
} else {
68+
var sessionRequest = new LootLockerSessionRequest(LootLockerConfig.current.deviceID);
69+
LootLockerAPIManager.Session(sessionRequest, (response) =>
70+
{
71+
CompleteCall(cacheServerRequest, OnServerResponse, response);
72+
});
73+
}
74+
75+
void CompleteCall(LootLockerServerRequest cacheServerRequest, Action<LootLockerResponse> OnServerResponse, LootLockerSessionResponse response)
4576
{
4677
if (response.success)
4778
{
@@ -72,7 +103,7 @@ protected override void RefreshTokenAndCompleteCall(LootLockerServerRequest cach
72103
res.hasError = true;
73104
OnServerResponse?.Invoke(res);
74105
}
75-
});
106+
}
76107
}
77108
}
78109
}

0 commit comments

Comments
 (0)