Get a cookie from Cordoba InAppBrowser in Ionic 2

I am creating a mobile version of a web application with Ionic 2 that uses SAML for SSO that runs on my client server. Right now we have an api that gets called when you donโ€™t go to a website that is redirected to your server for SSO and then returns to our server when you log in. Then in the browser there is a cookie for storage in which the user logs into the system.

I need to take this cookie and somehow get it in my Ionic app. I know that you cannot transfer cookies from InAppBrowser back to the application, but there must be some way to return it. Enough applications use Twitter, Facebook, etc. That I assume that there is something simple that I am missing.

+5
source share
1 answer

Yes, this is known to be difficult due to domain policy, and inAppBrowser is a new instance that does not allow the previous web view to access it.

There is a method, but using the InAppBrowser executeScript() method, which allows you to execute JavaScript in the window that opens.

 var win = window.open( "http://icenium.com", "_blank", "EnableViewPortScale=yes" ); win.addEventListener( "loadstop", function() { win.executeScript({ code: "alert( 'hello' );" }); }); 

You can even provide a callback to retrieve values โ€‹โ€‹from an open Window.

 var win = window.open( "http://icenium.com", "_blank", "EnableViewPortScale=yes" ); win.addEventListener( "loadstop", function() { win.executeScript( { code: "document.body.innerHTML" }, function( values ) { alert( values[ 0 ] ); } ); }); 

Then you can use the return value to store it in local storage

This site contains great code to help you.

+2
source

All Articles