@@ -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 ( "" ) ;
112+ var redirectUrl = KeyStoreManagerUtils . getPreferencesData ( KeyStoreManagerUtils . REDIRECT_URL ) ;
113+ authorizeSession ( "" , redirectUrl ) ;
112114
113115 JsonSerializerSettings settings = new JsonSerializerSettings
114116 {
@@ -264,13 +266,21 @@ private void IncomingHttpRequest(IAsyncResult result)
264266
265267 private async void processRequest ( string path , LoginParams loginParams = null )
266268 {
269+ redirectUrl = this . initParams [ "redirectUrl" ] . ToString ( ) ;
270+ if ( redirectUrl . EndsWith ( "/" ) )
271+ {
272+ redirectUrl = redirectUrl . TrimEnd ( '/' ) ;
273+ }
274+
267275#if UNITY_STANDALONE || UNITY_EDITOR
268276 this . initParams [ "redirectUrl" ] = StartLocalWebserver ( ) ;
277+ redirectUrl = this . initParams [ "redirectUrl" ] . ToString ( ) . Replace ( "/complete/" , "" ) ;
269278#elif UNITY_WEBGL
270279 this . initParams [ "redirectUrl" ] = Utils . GetCurrentURL ( ) ;
271280#endif
272281
273282 loginParams . redirectUrl = loginParams . redirectUrl ?? new Uri ( this . initParams [ "redirectUrl" ] . ToString ( ) ) ;
283+ //Debug.Log("loginParams.redirectUrl: =>" + loginParams.redirectUrl);
274284 Dictionary < string , object > paramMap = new Dictionary < string , object > ( ) ;
275285 paramMap [ "options" ] = this . initParams ;
276286 paramMap [ "params" ] = loginParams == null ? ( object ) new Dictionary < string , object > ( ) : ( object ) loginParams ;
@@ -287,7 +297,7 @@ private async void processRequest(string path, LoginParams loginParams = null)
287297 new JsonSerializerSettings
288298 {
289299 NullValueHandling = NullValueHandling . Ignore
290- } ) , 600 ) ;
300+ } ) , 600 , "*" ) ;
291301
292302 if ( ! string . IsNullOrEmpty ( loginId ) )
293303 {
@@ -326,8 +336,14 @@ public async void launchWalletServices(ChainConfig chainConfig, string path = "w
326336 string sessionId = KeyStoreManagerUtils . getPreferencesData ( KeyStoreManagerUtils . SESSION_ID ) ;
327337 if ( ! string . IsNullOrEmpty ( sessionId ) )
328338 {
339+ redirectUrl = this . initParams [ "redirectUrl" ] . ToString ( ) ;
340+ if ( redirectUrl . EndsWith ( "/" ) )
341+ {
342+ redirectUrl = redirectUrl . TrimEnd ( '/' ) ;
343+ }
329344 #if UNITY_STANDALONE || UNITY_EDITOR
330345 this . initParams [ "redirectUrl" ] = StartLocalWebserver ( ) ;
346+ redirectUrl = this . initParams [ "redirectUrl" ] . ToString ( ) . Replace ( "/complete/" , "" ) ;
331347 #elif UNITY_WEBGL
332348 this . initParams [ "redirectUrl" ] = Utils . GetCurrentURL ( ) ;
333349 #endif
@@ -341,7 +357,7 @@ public async void launchWalletServices(ChainConfig chainConfig, string path = "w
341357 new JsonSerializerSettings
342358 {
343359 NullValueHandling = NullValueHandling . Ignore
344- } ) , 600 ) ;
360+ } ) , 600 , "*" ) ;
345361
346362 if ( ! string . IsNullOrEmpty ( loginId ) )
347363 {
@@ -425,9 +441,10 @@ public void setResultUrl(Uri uri)
425441 }
426442 string sessionId = sessionResponse . sessionId ;
427443 this . Enqueue ( ( ) => KeyStoreManagerUtils . savePreferenceData ( KeyStoreManagerUtils . SESSION_ID , sessionId ) ) ;
444+ this . Enqueue ( ( ) => KeyStoreManagerUtils . savePreferenceData ( KeyStoreManagerUtils . REDIRECT_URL , redirectUrl ) ) ;
428445
429446 //call authorize session API
430- this . Enqueue ( ( ) => authorizeSession ( sessionId ) ) ;
447+ this . Enqueue ( ( ) => authorizeSession ( sessionId , redirectUrl ) ) ;
431448
432449#if ! UNITY_EDITOR && UNITY_WEBGL
433450 if ( this . web3AuthResponse != null )
@@ -536,8 +553,14 @@ public async void request(ChainConfig chainConfig, string method, JArray request
536553 string sessionId = KeyStoreManagerUtils . getPreferencesData ( KeyStoreManagerUtils . SESSION_ID ) ;
537554 if ( ! string . IsNullOrEmpty ( sessionId ) )
538555 {
556+ redirectUrl = this . initParams [ "redirectUrl" ] . ToString ( ) ;
557+ if ( redirectUrl . EndsWith ( "/" ) )
558+ {
559+ redirectUrl = redirectUrl . TrimEnd ( '/' ) ;
560+ }
539561 #if UNITY_STANDALONE || UNITY_EDITOR
540562 this . initParams [ "redirectUrl" ] = StartLocalWebserver ( ) ;
563+ redirectUrl = this . initParams [ "redirectUrl" ] . ToString ( ) . Replace ( "/complete/" , "" ) ;
541564 #elif UNITY_WEBGL
542565 this . initParams [ "redirectUrl" ] = Utils . GetCurrentURL ( ) ;
543566 #endif
@@ -550,7 +573,7 @@ public async void request(ChainConfig chainConfig, string method, JArray request
550573 new JsonSerializerSettings
551574 {
552575 NullValueHandling = NullValueHandling . Ignore
553- } ) , 60000 ) ;
576+ } ) , 600 , "*" ) ;
554577
555578 if ( ! string . IsNullOrEmpty ( loginId ) )
556579 {
@@ -598,7 +621,7 @@ public async void request(ChainConfig chainConfig, string method, JArray request
598621 }
599622 }
600623
601- private void authorizeSession ( string newSessionId )
624+ private void authorizeSession ( string newSessionId , string origin )
602625 {
603626 string sessionId = "" ;
604627 if ( string . IsNullOrEmpty ( newSessionId ) )
@@ -614,7 +637,8 @@ private void authorizeSession(string newSessionId)
614637 if ( ! string . IsNullOrEmpty ( sessionId ) )
615638 {
616639 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 =>
618642 {
619643 if ( response != null )
620644 {
@@ -641,6 +665,7 @@ private void authorizeSession(string newSessionId)
641665 if ( ! string . IsNullOrEmpty ( this . web3AuthResponse . sessionId ) )
642666 {
643667 KeyStoreManagerUtils . savePreferenceData ( KeyStoreManagerUtils . SESSION_ID , this . web3AuthResponse . sessionId ) ;
668+ //Debug.Log("redirectUrl: =>" + redirectUrl);
644669 }
645670
646671 if ( ! string . IsNullOrEmpty ( web3AuthResponse . userInfo ? . dappShare ) )
@@ -665,10 +690,11 @@ private void authorizeSession(string newSessionId)
665690 private void sessionTimeOutAPI ( )
666691 {
667692 string sessionId = KeyStoreManagerUtils . getPreferencesData ( KeyStoreManagerUtils . SESSION_ID ) ;
693+ string redirectUrl = KeyStoreManagerUtils . getPreferencesData ( KeyStoreManagerUtils . REDIRECT_URL ) ;
668694 if ( ! string . IsNullOrEmpty ( sessionId ) )
669695 {
670696 var pubKey = KeyStoreManagerUtils . getPubKey ( sessionId ) ;
671- StartCoroutine ( Web3AuthApi . getInstance ( ) . authorizeSession ( pubKey , ( response =>
697+ StartCoroutine ( Web3AuthApi . getInstance ( ) . authorizeSession ( pubKey , redirectUrl , ( response =>
672698 {
673699 if ( response != null )
674700 {
@@ -724,7 +750,7 @@ private void sessionTimeOutAPI()
724750 }
725751 }
726752
727- private async Task < string > createSession ( string data , long sessionTime )
753+ private async Task < string > createSession ( string data , long sessionTime , string allowedOrigin )
728754 {
729755 TaskCompletionSource < string > createSessionResponse = new TaskCompletionSource < string > ( ) ;
730756 var newSessionKey = KeyStoreManagerUtils . generateRandomSessionKey ( ) ;
@@ -756,15 +782,15 @@ private async Task<string> createSession(string data, long sessionTime)
756782 newSessionKey ,
757783 jsonData
758784 ) ,
759- timeout = Math . Min ( sessionTime , 30 * 86400 )
785+ timeout = Math . Min ( sessionTime , 30 * 86400 ) ,
786+ allowedOrigin = allowedOrigin
760787 } , result =>
761788 {
762789 if ( result != null )
763790 {
764791 try
765792 {
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)
768794 createSessionResponse . SetResult ( newSessionKey ) ;
769795 }
770796 catch ( Exception ex )
0 commit comments