Skip to content

Commit 24d4ba7

Browse files
committed
feat: auth-services v9 updates
Signed-off-by: Gaurav Goel <[email protected]>
1 parent 7c21883 commit 24d4ba7

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

Assets/Plugins/Web3AuthSDK/Api/Models/LogoutApiRequest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ public class LogoutApiRequest
88
public string data { get; set; }
99
public string signature { get; set; }
1010
public long timeout { get; set; }
11+
public string allowedOrigin { get; set; } = "*";
1112
}

Assets/Plugins/Web3AuthSDK/Api/Web3AuthApi.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public class Web3AuthApi
1010
{
1111
static Web3AuthApi instance;
12-
static string baseAddress = "https://session.web3auth.io";
12+
static string baseAddress = "https://session.web3auth.io/v2";
1313

1414
public static Web3AuthApi getInstance()
1515
{
@@ -18,24 +18,25 @@ public static Web3AuthApi getInstance()
1818
return instance;
1919
}
2020

21-
public IEnumerator authorizeSession(string key, Action<StoreApiResponse> callback)
21+
public IEnumerator authorizeSession(string key, string origin, Action<StoreApiResponse> callback)
2222
{
2323
//var requestURL = $"{baseAddress}/store/get?key={key}";
2424
//var request = UnityWebRequest.Get(requestURL);
2525
WWWForm data = new WWWForm();
2626
data.AddField("key", key);
2727

2828
var request = UnityWebRequest.Post($"{baseAddress}/store/get", data);
29+
request.SetRequestHeader("origin", origin);
2930

3031
yield return request.SendWebRequest();
31-
// Debug.Log("baseAddress =>" + baseAddress);
32-
// Debug.Log("key =>" + key);
33-
// Debug.Log("request URL =>"+ requestURL);
34-
// Debug.Log("request.isNetworkError =>" + request.isNetworkError);
35-
// Debug.Log("request.isHttpError =>" + request.isHttpError);
36-
// Debug.Log("request.isHttpError =>" + request.error);
37-
// Debug.Log("request.result =>" + request.result);
38-
// Debug.Log("request.downloadHandler.text =>" + request.downloadHandler.text);
32+
Debug.Log("baseAddress =>" + baseAddress);
33+
Debug.Log("key =>" + key);
34+
Debug.Log("request URL =>"+ request);
35+
Debug.Log("request.isNetworkError =>" + request.isNetworkError);
36+
Debug.Log("request.isHttpError =>" + request.isHttpError);
37+
Debug.Log("request.isHttpError =>" + request.error);
38+
Debug.Log("request.result =>" + request.result);
39+
Debug.Log("request.downloadHandler.text =>" + request.downloadHandler.text);
3940
if (request.result == UnityWebRequest.Result.Success)
4041
{
4142
string result = request.downloadHandler.text;

Assets/Plugins/Web3AuthSDK/Types/Web3AuthOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ public class Web3AuthOptions {
1111
public string sdkUrl {
1212
get {
1313
if (buildEnv == Web3Auth.BuildEnv.STAGING)
14-
return "https://staging-auth.web3auth.io/v8";
14+
return "https://staging-auth.web3auth.io/v9";
1515
else if (buildEnv == Web3Auth.BuildEnv.TESTING)
1616
return "https://develop-auth.web3auth.io";
1717
else
18-
return "https://auth.web3auth.io/v8";
18+
return "https://auth.web3auth.io/v9";
1919
}
2020
set { }
2121
}

Assets/Plugins/Web3AuthSDK/Web3Auth.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public async void setOptions(Web3AuthOptions web3AuthOptions)
108108
{
109109
throw new Exception("Failed to fetch project config. Please try again later.");
110110
} else {
111-
authorizeSession("");
111+
authorizeSession("", this.web3AuthOptions.redirectUrl.ToString());
112112

113113
JsonSerializerSettings settings = new JsonSerializerSettings
114114
{
@@ -287,7 +287,7 @@ private async void processRequest(string path, LoginParams loginParams = null)
287287
new JsonSerializerSettings
288288
{
289289
NullValueHandling = NullValueHandling.Ignore
290-
}), 600);
290+
}), 600, "*");
291291

292292
if (!string.IsNullOrEmpty(loginId))
293293
{
@@ -341,7 +341,7 @@ public async void launchWalletServices(ChainConfig chainConfig, string path = "w
341341
new JsonSerializerSettings
342342
{
343343
NullValueHandling = NullValueHandling.Ignore
344-
}), 600);
344+
}), 600, "*");
345345

346346
if (!string.IsNullOrEmpty(loginId))
347347
{
@@ -427,7 +427,7 @@ public void setResultUrl(Uri uri)
427427
this.Enqueue(() => KeyStoreManagerUtils.savePreferenceData(KeyStoreManagerUtils.SESSION_ID, sessionId));
428428

429429
//call authorize session API
430-
this.Enqueue(() => authorizeSession(sessionId));
430+
this.Enqueue(() => authorizeSession(sessionId, this.web3AuthOptions.redirectUrl.ToString()));
431431

432432
#if !UNITY_EDITOR && UNITY_WEBGL
433433
if (this.web3AuthResponse != null)
@@ -550,7 +550,7 @@ public async void request(ChainConfig chainConfig, string method, JArray request
550550
new JsonSerializerSettings
551551
{
552552
NullValueHandling = NullValueHandling.Ignore
553-
}), 60000);
553+
}), 600, "*");
554554

555555
if (!string.IsNullOrEmpty(loginId))
556556
{
@@ -598,7 +598,7 @@ public async void request(ChainConfig chainConfig, string method, JArray request
598598
}
599599
}
600600

601-
private void authorizeSession(string newSessionId)
601+
private void authorizeSession(string newSessionId, string origin)
602602
{
603603
string sessionId = "";
604604
if (string.IsNullOrEmpty(newSessionId))
@@ -614,7 +614,9 @@ private void authorizeSession(string newSessionId)
614614
if (!string.IsNullOrEmpty(sessionId))
615615
{
616616
var pubKey = KeyStoreManagerUtils.getPubKey(sessionId);
617-
StartCoroutine(Web3AuthApi.getInstance().authorizeSession(pubKey, (response =>
617+
Debug.Log("pubKey: =>" + pubKey);
618+
Debug.Log("origin: =>" + origin);
619+
StartCoroutine(Web3AuthApi.getInstance().authorizeSession(pubKey, origin, (response =>
618620
{
619621
if (response != null)
620622
{
@@ -668,7 +670,7 @@ private void sessionTimeOutAPI()
668670
if (!string.IsNullOrEmpty(sessionId))
669671
{
670672
var pubKey = KeyStoreManagerUtils.getPubKey(sessionId);
671-
StartCoroutine(Web3AuthApi.getInstance().authorizeSession(pubKey, (response =>
673+
StartCoroutine(Web3AuthApi.getInstance().authorizeSession(pubKey, this.web3AuthOptions.redirectUrl.ToString(), (response =>
672674
{
673675
if (response != null)
674676
{
@@ -724,7 +726,7 @@ private void sessionTimeOutAPI()
724726
}
725727
}
726728

727-
private async Task<string> createSession(string data, long sessionTime)
729+
private async Task<string> createSession(string data, long sessionTime, string allowedOrigin)
728730
{
729731
TaskCompletionSource<string> createSessionResponse = new TaskCompletionSource<string>();
730732
var newSessionKey = KeyStoreManagerUtils.generateRandomSessionKey();
@@ -756,7 +758,8 @@ private async Task<string> createSession(string data, long sessionTime)
756758
newSessionKey,
757759
jsonData
758760
),
759-
timeout = Math.Min(sessionTime, 7 * 86400)
761+
timeout = Math.Min(sessionTime, 7 * 86400),
762+
allowedOrigin = allowedOrigin
760763
}, result =>
761764
{
762765
if (result != null)

0 commit comments

Comments
 (0)