@@ -64,6 +64,7 @@ public static void setSignResponse(SignResponse _response)
64
64
65
65
[ SerializeField ]
66
66
private Web3Auth . Network network ;
67
+ private string redirectUrl ;
67
68
68
69
private static readonly Queue < Action > _executionQueue = new Queue < Action > ( ) ;
69
70
@@ -108,7 +109,8 @@ public async void setOptions(Web3AuthOptions web3AuthOptions)
108
109
{
109
110
throw new Exception ( "Failed to fetch project config. Please try again later." ) ;
110
111
} else {
111
- authorizeSession ( "" ) ;
112
+ var redirectUrl = KeyStoreManagerUtils . getPreferencesData ( KeyStoreManagerUtils . REDIRECT_URL ) ;
113
+ authorizeSession ( "" , redirectUrl ) ;
112
114
113
115
JsonSerializerSettings settings = new JsonSerializerSettings
114
116
{
@@ -264,13 +266,21 @@ private void IncomingHttpRequest(IAsyncResult result)
264
266
265
267
private async void processRequest ( string path , LoginParams loginParams = null )
266
268
{
269
+ redirectUrl = this . initParams [ "redirectUrl" ] . ToString ( ) ;
270
+ if ( redirectUrl . EndsWith ( "/" ) )
271
+ {
272
+ redirectUrl = redirectUrl . TrimEnd ( '/' ) ;
273
+ }
274
+
267
275
#if UNITY_STANDALONE || UNITY_EDITOR
268
276
this . initParams [ "redirectUrl" ] = StartLocalWebserver ( ) ;
277
+ redirectUrl = this . initParams [ "redirectUrl" ] . ToString ( ) . Replace ( "/complete/" , "" ) ;
269
278
#elif UNITY_WEBGL
270
279
this . initParams [ "redirectUrl" ] = Utils . GetCurrentURL ( ) ;
271
280
#endif
272
281
273
282
loginParams . redirectUrl = loginParams . redirectUrl ?? new Uri ( this . initParams [ "redirectUrl" ] . ToString ( ) ) ;
283
+ //Debug.Log("loginParams.redirectUrl: =>" + loginParams.redirectUrl);
274
284
Dictionary < string , object > paramMap = new Dictionary < string , object > ( ) ;
275
285
paramMap [ "options" ] = this . initParams ;
276
286
paramMap [ "params" ] = loginParams == null ? ( object ) new Dictionary < string , object > ( ) : ( object ) loginParams ;
@@ -287,7 +297,7 @@ private async void processRequest(string path, LoginParams loginParams = null)
287
297
new JsonSerializerSettings
288
298
{
289
299
NullValueHandling = NullValueHandling . Ignore
290
- } ) , 600 ) ;
300
+ } ) , 600 , "*" ) ;
291
301
292
302
if ( ! string . IsNullOrEmpty ( loginId ) )
293
303
{
@@ -326,8 +336,14 @@ public async void launchWalletServices(ChainConfig chainConfig, string path = "w
326
336
string sessionId = KeyStoreManagerUtils . getPreferencesData ( KeyStoreManagerUtils . SESSION_ID ) ;
327
337
if ( ! string . IsNullOrEmpty ( sessionId ) )
328
338
{
339
+ redirectUrl = this . initParams [ "redirectUrl" ] . ToString ( ) ;
340
+ if ( redirectUrl . EndsWith ( "/" ) )
341
+ {
342
+ redirectUrl = redirectUrl . TrimEnd ( '/' ) ;
343
+ }
329
344
#if UNITY_STANDALONE || UNITY_EDITOR
330
345
this . initParams [ "redirectUrl" ] = StartLocalWebserver ( ) ;
346
+ redirectUrl = this . initParams [ "redirectUrl" ] . ToString ( ) . Replace ( "/complete/" , "" ) ;
331
347
#elif UNITY_WEBGL
332
348
this . initParams [ "redirectUrl" ] = Utils . GetCurrentURL ( ) ;
333
349
#endif
@@ -341,7 +357,7 @@ public async void launchWalletServices(ChainConfig chainConfig, string path = "w
341
357
new JsonSerializerSettings
342
358
{
343
359
NullValueHandling = NullValueHandling . Ignore
344
- } ) , 600 ) ;
360
+ } ) , 600 , "*" ) ;
345
361
346
362
if ( ! string . IsNullOrEmpty ( loginId ) )
347
363
{
@@ -425,9 +441,10 @@ public void setResultUrl(Uri uri)
425
441
}
426
442
string sessionId = sessionResponse . sessionId ;
427
443
this . Enqueue ( ( ) => KeyStoreManagerUtils . savePreferenceData ( KeyStoreManagerUtils . SESSION_ID , sessionId ) ) ;
444
+ this . Enqueue ( ( ) => KeyStoreManagerUtils . savePreferenceData ( KeyStoreManagerUtils . REDIRECT_URL , redirectUrl ) ) ;
428
445
429
446
//call authorize session API
430
- this . Enqueue ( ( ) => authorizeSession ( sessionId ) ) ;
447
+ this . Enqueue ( ( ) => authorizeSession ( sessionId , redirectUrl ) ) ;
431
448
432
449
#if ! UNITY_EDITOR && UNITY_WEBGL
433
450
if ( this . web3AuthResponse != null )
@@ -536,8 +553,14 @@ public async void request(ChainConfig chainConfig, string method, JArray request
536
553
string sessionId = KeyStoreManagerUtils . getPreferencesData ( KeyStoreManagerUtils . SESSION_ID ) ;
537
554
if ( ! string . IsNullOrEmpty ( sessionId ) )
538
555
{
556
+ redirectUrl = this . initParams [ "redirectUrl" ] . ToString ( ) ;
557
+ if ( redirectUrl . EndsWith ( "/" ) )
558
+ {
559
+ redirectUrl = redirectUrl . TrimEnd ( '/' ) ;
560
+ }
539
561
#if UNITY_STANDALONE || UNITY_EDITOR
540
562
this . initParams [ "redirectUrl" ] = StartLocalWebserver ( ) ;
563
+ redirectUrl = this . initParams [ "redirectUrl" ] . ToString ( ) . Replace ( "/complete/" , "" ) ;
541
564
#elif UNITY_WEBGL
542
565
this . initParams [ "redirectUrl" ] = Utils . GetCurrentURL ( ) ;
543
566
#endif
@@ -550,7 +573,7 @@ public async void request(ChainConfig chainConfig, string method, JArray request
550
573
new JsonSerializerSettings
551
574
{
552
575
NullValueHandling = NullValueHandling . Ignore
553
- } ) , 60000 ) ;
576
+ } ) , 600 , "*" ) ;
554
577
555
578
if ( ! string . IsNullOrEmpty ( loginId ) )
556
579
{
@@ -598,7 +621,7 @@ public async void request(ChainConfig chainConfig, string method, JArray request
598
621
}
599
622
}
600
623
601
- private void authorizeSession ( string newSessionId )
624
+ private void authorizeSession ( string newSessionId , string origin )
602
625
{
603
626
string sessionId = "" ;
604
627
if ( string . IsNullOrEmpty ( newSessionId ) )
@@ -614,7 +637,8 @@ private void authorizeSession(string newSessionId)
614
637
if ( ! string . IsNullOrEmpty ( sessionId ) )
615
638
{
616
639
var pubKey = KeyStoreManagerUtils . getPubKey ( sessionId ) ;
617
- StartCoroutine ( Web3AuthApi . getInstance ( ) . authorizeSession ( pubKey , ( response =>
640
+ //Debug.Log("origin: =>" + origin);
641
+ StartCoroutine ( Web3AuthApi . getInstance ( ) . authorizeSession ( pubKey , origin , ( response =>
618
642
{
619
643
if ( response != null )
620
644
{
@@ -641,6 +665,7 @@ private void authorizeSession(string newSessionId)
641
665
if ( ! string . IsNullOrEmpty ( this . web3AuthResponse . sessionId ) )
642
666
{
643
667
KeyStoreManagerUtils . savePreferenceData ( KeyStoreManagerUtils . SESSION_ID , this . web3AuthResponse . sessionId ) ;
668
+ //Debug.Log("redirectUrl: =>" + redirectUrl);
644
669
}
645
670
646
671
if ( ! string . IsNullOrEmpty ( web3AuthResponse . userInfo ? . dappShare ) )
@@ -665,10 +690,11 @@ private void authorizeSession(string newSessionId)
665
690
private void sessionTimeOutAPI ( )
666
691
{
667
692
string sessionId = KeyStoreManagerUtils . getPreferencesData ( KeyStoreManagerUtils . SESSION_ID ) ;
693
+ string redirectUrl = KeyStoreManagerUtils . getPreferencesData ( KeyStoreManagerUtils . REDIRECT_URL ) ;
668
694
if ( ! string . IsNullOrEmpty ( sessionId ) )
669
695
{
670
696
var pubKey = KeyStoreManagerUtils . getPubKey ( sessionId ) ;
671
- StartCoroutine ( Web3AuthApi . getInstance ( ) . authorizeSession ( pubKey , ( response =>
697
+ StartCoroutine ( Web3AuthApi . getInstance ( ) . authorizeSession ( pubKey , redirectUrl , ( response =>
672
698
{
673
699
if ( response != null )
674
700
{
@@ -724,7 +750,7 @@ private void sessionTimeOutAPI()
724
750
}
725
751
}
726
752
727
- private async Task < string > createSession ( string data , long sessionTime )
753
+ private async Task < string > createSession ( string data , long sessionTime , string allowedOrigin )
728
754
{
729
755
TaskCompletionSource < string > createSessionResponse = new TaskCompletionSource < string > ( ) ;
730
756
var newSessionKey = KeyStoreManagerUtils . generateRandomSessionKey ( ) ;
@@ -756,15 +782,15 @@ private async Task<string> createSession(string data, long sessionTime)
756
782
newSessionKey ,
757
783
jsonData
758
784
) ,
759
- timeout = Math . Min ( sessionTime , 30 * 86400 )
785
+ timeout = Math . Min ( sessionTime , 30 * 86400 ) ,
786
+ allowedOrigin = allowedOrigin
760
787
} , result =>
761
788
{
762
789
if ( result != null )
763
790
{
764
791
try
765
792
{
766
- // Debug.Log("newSessionKey before saving into keystore =>" + newSessionKey);
767
- this . Enqueue ( ( ) => KeyStoreManagerUtils . savePreferenceData ( KeyStoreManagerUtils . SESSION_ID , newSessionKey ) ) ;
793
+ // Debug.Log("newSessionKey before saving into keystore =>" + newSessionKey)
768
794
createSessionResponse . SetResult ( newSessionKey ) ;
769
795
}
770
796
catch ( Exception ex )
0 commit comments