-
-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sharing cookies between HTTP-Plugin, WKWebView and InAppBrowser #330
Comments
Some follow up on this - I know a similar question was answered in a discussion here. asked by @varunkumarm. @silkimen replied:
[EDIT 05.11.2020] What I have found out until now (all XHR requests made with HTTP plugin):
If only the session cookie would be added it would work pretty well. At the same time, if in further requests XHR would "restore" session based on rememberMe, it would have to make it available for the WebView do that requests made directly from there also get the proper session. |
@silkimen is here any update or comment from your end on this? |
I can only add that I haven't abandoned this topic, but having all the problems listed above I have released an app update that is still using UIWebView. I will have to work on a new version before end of year that will most likely include a different session management that is not so heavily dependent on cookies (JWT?), but that requires broad server side changes. |
Hi guys, But @maciej-zabielski already mentioned this here:
We had a similar issue in one of our projects at work. We've used an InAppBrowser fork which adds a getter function to access the cookies. You can use setCookie() to copy the cookies into this plugin's cookie storage afterwards. But unfortunately, there are 1.8k forks of InAppBrowser and I can't remember which fork it was. |
Hi guys, |
There must be some cookie sharing that happens on underlying connection that HTTP-plugin is using. Even if its not explicit, but as I have mentioned, we get two cookies returned to the InAppBrowser. Session cookie and RememberMe. RememberMe is "taken over" by HTTP-plugin. Even if there is nothing in the localstorage used by plugin, the cookie will be added. I don't understand how session cookie is kept "secret" by the native code. They are basically the same. On the server side I can see two sessions one that comes from InApp and one from XHR plugin. @ikosta it's interesting to see if it will be possible to implement solid "cookie-sync" using your extra plugin. With session cookies it's also important that we can clear them when logout happens. So we should make sure that everything gets removed from underlying native layer and from localstorage. |
@ikosta that's very interesting. When I started developing this plugin (it was a fork that diverged long time ago), I wanted to implement cookie handling in the native code. But the problem (back then) was that I kept loosing cookie data on iOS. Then I decided to use tough-cookie and implement cookie handling in the JS runtime, which made it also easier to develop features for both platforms and it just worked. |
Hi @ikosta, ¿Is your cordova-plugin-cookies working even it's not released? I need a solution like that in my current project, so I can help to test it and give you feedback. Thank you in advance
|
@nooblado yes it is. Had to release an app with first bugfix Version so I had no time to release the plugin. Will update the readme and release it later today. |
@silkimen an implementation of an unified cookie-store for webview/http-plugin would be very nice but it’s also an edge-case. In our apps we use plenty of external crm api’s with multiple connection settings and from only three of them we need the cookie. One can be taken care of with just the http-plugin and for the other two we need that solution. |
@nooblado @maciej-zabielski @silkimen I just published the plugin cordova-plugin-cookies |
Thank you @ikosta! I'm going to add your plugin to my app. Great job!! |
Thanks @ikosta, I'll add this into the FAQ list 👍 |
Closing this, feel free to open a new issue, if this won't solve your problem! 👍 |
Hi, I'm trying to solve the following problem that I think is quite typical for many developers?
My app loads in main WebView (based on
cordova-plugin-ionic-webview
). It tries to make a call to server using this HTTP-Plugin as regular XHR would be blocked due to CORS restrictions.When it gets Unauthorised response it will open up InAppBrowser (
cordova-plugin-inappbrowser
- WKWebView based as well) to show user login options (login must support ADFS redirects etc, so easy login via XHR/Basic is not an option here). I know the login will return proper cookies to InAppBrowser WebView - I can see them in Safari console. Cookies will be marked as secure/httpOnly.After login the InAppBrowser is closed and the app will make another attempt to load data via HTTP-Plugin. Unfortunately something goes wrong here, as the session cookies are not accepted.
Also main WebView should be able to make plane GET requests, e.g. for image resources (non-xhr). Although, the main WebView will have different domain than InAppBrowser ("real" domain vs localhost app).
Should these cookies be theoretically shared between all these instances?
Form Cordova-WkWebView docs: "This plugin creates a shared WKProcessPool which ensures the cookie sharing happens correctly across WKWebView instances. CDVWKProcessPoolFactory class can be used to obtain the shared WKProcessPool instance if app creates WKWebView outside of this plugin."
Since WKWebView plugin implementation can use shared cookie storage for both main WebView and InAppBrowser, it should also be possible for HTTP-Plugin to access the same pool. As a result we could:
I'm not sure if this is the case for Ionic version as well? I have zero knowledge on iOS native development so that makes things a bit harder :( Similar approach (without HTTP plugin) worked just fine with UIWebView that did not restrict cookie or XHR/CORS.
I would greatly appreciate some feedback from anyone who managed to run that kind of scenario!
The text was updated successfully, but these errors were encountered: