Skip to content

Commit

Permalink
Merge pull request #25 from Web3Auth/testing
Browse files Browse the repository at this point in the history
Fix iOS and logout
  • Loading branch information
yashovardhan authored Oct 26, 2023
2 parents fff113c + 09f1738 commit a396842
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
Binary file modified .DS_Store
Binary file not shown.
59 changes: 41 additions & 18 deletions Assets/Plugins/Web3AuthSDK/Api/Web3AuthApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@ public static Web3AuthApi getInstance()

public IEnumerator authorizeSession(string key, Action<StoreApiResponse> callback)
{
var request = UnityWebRequest.Get($"{baseAddress}/store/get?key={key}");
yield return request.SendWebRequest();
//var requestURL = $"{baseAddress}/store/get?key={key}";
//var request = UnityWebRequest.Get(requestURL);
WWWForm data = new WWWForm();
data.AddField("key", key);

var request = UnityWebRequest.Post($"{baseAddress}/store/get", data);

yield return request.SendWebRequest();
// Debug.Log("baseAddress =>" + baseAddress);
// Debug.Log("key =>" + key);
// //Debug.Log("request URL =>"+ requestURL);
// Debug.Log("request.isNetworkError =>" + request.isNetworkError);
// Debug.Log("request.isHttpError =>" + request.isHttpError);
// Debug.Log("request.isHttpError =>" + request.error);
// Debug.Log("request.result =>" + request.result);
// Debug.Log("request.downloadHandler.text =>" + request.downloadHandler.text);
if (request.result == UnityWebRequest.Result.Success)
{
string result = request.downloadHandler.text;
Expand All @@ -38,10 +51,20 @@ public IEnumerator logout(LogoutApiRequest logoutApiRequest, Action<JObject> cal
data.AddField("data", logoutApiRequest.data);
data.AddField("signature", logoutApiRequest.signature);
data.AddField("timeout", logoutApiRequest.timeout.ToString());
// Debug.Log("key during logout session =>" + logoutApiRequest.key);

var request = UnityWebRequest.Post($"{baseAddress}/store/set", data);
yield return request.SendWebRequest();

// Debug.Log("baseAddress =>" + baseAddress);
// Debug.Log("key =>" + logoutApiRequest.key);
// Debug.Log("request URL =>"+ requestURL);
// Debug.Log("request.isNetworkError =>" + request.isNetworkError);
// Debug.Log("request.isHttpError =>" + request.isHttpError);
// Debug.Log("request.isHttpError =>" + request.error);
// Debug.Log("request.result =>" + request.result);
// Debug.Log("request.downloadHandler.text =>" + request.downloadHandler.text);

if (request.result == UnityWebRequest.Result.Success)
{
string result = request.downloadHandler.text;
Expand All @@ -52,22 +75,22 @@ public IEnumerator logout(LogoutApiRequest logoutApiRequest, Action<JObject> cal
}

public IEnumerator createSession(LogoutApiRequest logoutApiRequest, Action<JObject> callback)
{
WWWForm data = new WWWForm();
data.AddField("key", logoutApiRequest.key);
data.AddField("data", logoutApiRequest.data);
data.AddField("signature", logoutApiRequest.signature);
data.AddField("timeout", logoutApiRequest.timeout.ToString());

var request = UnityWebRequest.Post($"{baseAddress}/store/set", data);
yield return request.SendWebRequest();
{
WWWForm data = new WWWForm();
data.AddField("key", logoutApiRequest.key);
data.AddField("data", logoutApiRequest.data);
data.AddField("signature", logoutApiRequest.signature);
data.AddField("timeout", logoutApiRequest.timeout.ToString());
// Debug.Log("key during create session =>" + logoutApiRequest.key);
var request = UnityWebRequest.Post($"{baseAddress}/store/set", data);
yield return request.SendWebRequest();

if (request.result == UnityWebRequest.Result.Success)
{
string result = request.downloadHandler.text;
callback(Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(result));
}
else
callback(null);
if (request.result == UnityWebRequest.Result.Success)
{
string result = request.downloadHandler.text;
callback(Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(result));
}
else
callback(null);
}
}
8 changes: 7 additions & 1 deletion Assets/Plugins/Web3AuthSDK/Web3Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ public void setResultUrl(Uri uri)
this.Enqueue(() => KeyStoreManagerUtils.savePreferenceData(KeyStoreManagerUtils.SESSION_ID, sessionId));

//call authorize session API
// Debug.Log("publickey after successful redirection from web. =>" + sessionId);
this.Enqueue(() => authorizeSession(sessionId));

#if !UNITY_EDITOR && UNITY_WEBGL
Expand Down Expand Up @@ -359,10 +360,12 @@ private void authorizeSession(string newSessionId)
if (string.IsNullOrEmpty(newSessionId))
{
sessionId = KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.SESSION_ID);
// Debug.Log("sessionId during authorizeSession in if part =>" + sessionId);
}
else
{
sessionId = newSessionId;
// Debug.Log("sessionId during authorizeSession in else part =>" + sessionId);
}

if (!string.IsNullOrEmpty(sessionId))
Expand Down Expand Up @@ -460,7 +463,8 @@ private void sessionTimeOutAPI()
try
{
KeyStoreManagerUtils.deletePreferencesData(KeyStoreManagerUtils.SESSION_ID);
KeyStoreManagerUtils.deletePreferencesData(web3AuthOptions.loginConfig?.Values.First()?.verifier);
if (web3AuthOptions.loginConfig != null)
KeyStoreManagerUtils.deletePreferencesData(web3AuthOptions.loginConfig?.Values.First()?.verifier);

this.Enqueue(() => this.onLogout?.Invoke());
}
Expand All @@ -480,6 +484,7 @@ private async Task<string> createSession(string data, long sessionTime)
{
TaskCompletionSource<string> createSessionResponse = new TaskCompletionSource<string>();
var newSessionKey = KeyStoreManagerUtils.generateRandomSessionKey();
// Debug.Log("newSessionKey =>" + newSessionKey);
var ephemKey = KeyStoreManagerUtils.getPubKey(newSessionKey);
var ivKey = KeyStoreManagerUtils.generateRandomBytes();

Expand Down Expand Up @@ -514,6 +519,7 @@ private async Task<string> createSession(string data, long sessionTime)
{
try
{
// Debug.Log("newSessionKey before saving into keystore =>" + newSessionKey);
this.Enqueue(() => KeyStoreManagerUtils.savePreferenceData(KeyStoreManagerUtils.SESSION_ID, newSessionKey));
createSessionResponse.SetResult(newSessionKey);
}
Expand Down

0 comments on commit a396842

Please sign in to comment.