Skip to content

Commit 4dca667

Browse files
committed
feat: auth-services v9 updates and session manager updates
Signed-off-by: Gaurav Goel <[email protected]>
1 parent 24d4ba7 commit 4dca667

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

Assets/Plugins/Web3AuthSDK/Api/Web3AuthApi.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,24 @@ public IEnumerator authorizeSession(string key, string origin, Action<StoreApiRe
2222
{
2323
//var requestURL = $"{baseAddress}/store/get?key={key}";
2424
//var request = UnityWebRequest.Get(requestURL);
25+
var requestURL = $"{baseAddress}/store/get";
26+
//Debug.Log("Request URL => " + requestURL);
27+
2528
WWWForm data = new WWWForm();
2629
data.AddField("key", key);
2730

28-
var request = UnityWebRequest.Post($"{baseAddress}/store/get", data);
31+
var request = UnityWebRequest.Post(requestURL, data);
2932
request.SetRequestHeader("origin", origin);
3033

3134
yield return request.SendWebRequest();
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);
35+
//Debug.Log("baseAddress =>" + baseAddress);
36+
//Debug.Log("key =>" + key);
37+
//Debug.Log("request URL =>"+ request);
38+
//Debug.Log("request.isNetworkError =>" + request.isNetworkError);
39+
//Debug.Log("request.isHttpError =>" + request.isHttpError);
40+
//Debug.Log("request.isHttpError =>" + request.error);
41+
//Debug.Log("request.result =>" + request.result);
42+
//Debug.Log("request.downloadHandler.text =>" + request.downloadHandler.text);
4043
if (request.result == UnityWebRequest.Result.Success)
4144
{
4245
string result = request.downloadHandler.text;

Assets/Plugins/Web3AuthSDK/Keystore/KeyStoreManagerUtils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class KeyStoreManagerUtils
2828
public static string IV_KEY = "ivKey";
2929
public static string EPHEM_PUBLIC_Key = "ephemPublicKey";
3030
public static string MAC = "mac";
31+
public static string REDIRECT_URL = "redirectUrl";
3132

3233
public static string getPubKey(string sessionId)
3334
{

Assets/Plugins/Web3AuthSDK/Web3Auth.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public static void setSignResponse(SignResponse _response)
6464

6565
[SerializeField]
6666
private Web3Auth.Network network;
67+
private string redirectUrl;
6768

6869
private static readonly Queue<Action> _executionQueue = new Queue<Action>();
6970

@@ -108,7 +109,8 @@ public async void setOptions(Web3AuthOptions web3AuthOptions)
108109
{
109110
throw new Exception("Failed to fetch project config. Please try again later.");
110111
} else {
111-
authorizeSession("", this.web3AuthOptions.redirectUrl.ToString());
112+
var redirectUrl = KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.REDIRECT_URL);
113+
authorizeSession("", redirectUrl);
112114

113115
JsonSerializerSettings settings = new JsonSerializerSettings
114116
{
@@ -264,8 +266,11 @@ private void IncomingHttpRequest(IAsyncResult result)
264266

265267
private async void processRequest(string path, LoginParams loginParams = null)
266268
{
269+
redirectUrl = this.initParams["redirectUrl"].ToString();
270+
267271
#if UNITY_STANDALONE || UNITY_EDITOR
268272
this.initParams["redirectUrl"] = StartLocalWebserver();
273+
redirectUrl = this.initParams["redirectUrl"].ToString().Replace("/complete/", "");
269274
#elif UNITY_WEBGL
270275
this.initParams["redirectUrl"] = Utils.GetCurrentURL();
271276
#endif
@@ -326,8 +331,10 @@ public async void launchWalletServices(ChainConfig chainConfig, string path = "w
326331
string sessionId = KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.SESSION_ID);
327332
if (!string.IsNullOrEmpty(sessionId))
328333
{
334+
redirectUrl = this.initParams["redirectUrl"].ToString();
329335
#if UNITY_STANDALONE || UNITY_EDITOR
330336
this.initParams["redirectUrl"] = StartLocalWebserver();
337+
redirectUrl = this.initParams["redirectUrl"].ToString().Replace("/complete/", "");
331338
#elif UNITY_WEBGL
332339
this.initParams["redirectUrl"] = Utils.GetCurrentURL();
333340
#endif
@@ -425,9 +432,11 @@ public void setResultUrl(Uri uri)
425432
}
426433
string sessionId = sessionResponse.sessionId;
427434
this.Enqueue(() => KeyStoreManagerUtils.savePreferenceData(KeyStoreManagerUtils.SESSION_ID, sessionId));
435+
this.Enqueue(() => KeyStoreManagerUtils.savePreferenceData(KeyStoreManagerUtils.REDIRECT_URL, redirectUrl));
428436

429437
//call authorize session API
430-
this.Enqueue(() => authorizeSession(sessionId, this.web3AuthOptions.redirectUrl.ToString()));
438+
//Debug.Log("redirectUrl: =>" + redirectUrl);
439+
this.Enqueue(() => authorizeSession(sessionId, redirectUrl));
431440

432441
#if !UNITY_EDITOR && UNITY_WEBGL
433442
if (this.web3AuthResponse != null)
@@ -536,8 +545,10 @@ public async void request(ChainConfig chainConfig, string method, JArray request
536545
string sessionId = KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.SESSION_ID);
537546
if (!string.IsNullOrEmpty(sessionId))
538547
{
548+
redirectUrl = this.initParams["redirectUrl"].ToString();
539549
#if UNITY_STANDALONE || UNITY_EDITOR
540550
this.initParams["redirectUrl"] = StartLocalWebserver();
551+
redirectUrl = this.initParams["redirectUrl"].ToString().Replace("/complete/", "");
541552
#elif UNITY_WEBGL
542553
this.initParams["redirectUrl"] = Utils.GetCurrentURL();
543554
#endif
@@ -614,8 +625,8 @@ private void authorizeSession(string newSessionId, string origin)
614625
if (!string.IsNullOrEmpty(sessionId))
615626
{
616627
var pubKey = KeyStoreManagerUtils.getPubKey(sessionId);
617-
Debug.Log("pubKey: =>" + pubKey);
618-
Debug.Log("origin: =>" + origin);
628+
//Debug.Log("pubKey: =>" + pubKey);
629+
//Debug.Log("origin: =>" + origin);
619630
StartCoroutine(Web3AuthApi.getInstance().authorizeSession(pubKey, origin, (response =>
620631
{
621632
if (response != null)
@@ -643,6 +654,7 @@ private void authorizeSession(string newSessionId, string origin)
643654
if (!string.IsNullOrEmpty(this.web3AuthResponse.sessionId))
644655
{
645656
KeyStoreManagerUtils.savePreferenceData(KeyStoreManagerUtils.SESSION_ID, this.web3AuthResponse.sessionId);
657+
//Debug.Log("redirectUrl: =>" + redirectUrl);
646658
}
647659

648660
if (!string.IsNullOrEmpty(web3AuthResponse.userInfo?.dappShare))
@@ -667,10 +679,11 @@ private void authorizeSession(string newSessionId, string origin)
667679
private void sessionTimeOutAPI()
668680
{
669681
string sessionId = KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.SESSION_ID);
682+
string redirectUrl = KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.REDIRECT_URL);
670683
if (!string.IsNullOrEmpty(sessionId))
671684
{
672685
var pubKey = KeyStoreManagerUtils.getPubKey(sessionId);
673-
StartCoroutine(Web3AuthApi.getInstance().authorizeSession(pubKey, this.web3AuthOptions.redirectUrl.ToString(), (response =>
686+
StartCoroutine(Web3AuthApi.getInstance().authorizeSession(pubKey, redirectUrl, (response =>
674687
{
675688
if (response != null)
676689
{

0 commit comments

Comments
 (0)