Skip to content
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

Cookies are not set/stored in iOS #300

Closed
FarhadG opened this issue Feb 5, 2019 · 14 comments
Closed

Cookies are not set/stored in iOS #300

FarhadG opened this issue Feb 5, 2019 · 14 comments

Comments

@FarhadG
Copy link

FarhadG commented Feb 5, 2019

Since we upgraded from the old UIWebView engine, we are not able to authenticate our users (using an external auth service), as none of the cookies sent by the APIs are being set in the this web view.

This is a major blocker for us and have been trying to determine what a good course of action is. If our assumptions are correct that cookies are not supported with this web view (which is very strange), we are going to try:

  • Proxy (not sure if you recommend a good plugin for this)
  • Native fetch (not sure if you recommend a good plugin for this)

Our stack:

  • Cordova
  • React
  • Fetch for calls
@allanevargas
Copy link

allanevargas commented Feb 7, 2019

I'm also experiencing the same issue.

After verifying details on my login.html it redirects it to menu.html and within this I do 3 separate HTTP $_GET requests. I inspected this through Firefox and I can see that the PHPSESSID are different for each request, while on Android it's completely fine and persists.

I haven't found a fix yet.

@FarhadG
Copy link
Author

FarhadG commented Feb 7, 2019

Yeah, this has been driving us crazy over the past couple of weeks, @aecvargas

@williamhilldevs
Copy link

Same issue here. I installed this plugin in my Cordova project and cookies work fine on Android but not on iOS! :(

@allanevargas
Copy link

@FarhadG @gabriele-bjss

I don't know if you guys have seen the potential solution found in this article:
https://novemberfive.co/blog/WKWebView-redirect-with-cookies

But I'm not entirely sure how to apply this fix to my ionic/cordova app as it is all in .swift and I am not familiar with swift at all.

@mesju
Copy link

mesju commented Feb 19, 2019

Same issue here. Would be nice if it will be fixed.

@jcesarmobile
Copy link
Member

I can get them to work, but just after killing the app as on #22, so going to close as duplicate.

Make sure you have xhr.withCredentials = true; if using XHR or credentials: 'include' if using fetch. That's required for cookie credentials to work on WKWebView while it wasn't on UIWebView.

They can also work if you set <preference name="Hostname" value="" /> to match the host where you are making the calls to, but it's not really a good solution as might break the Android app unless you change the scheme to not match your server one. (I.E. if you call to https://yourserver.com/file.json and you have <preference name="Hostname" value="yourserver.com" /> and <preference name="Scheme" value="https" /> it will be intercepted and look for a local file instead of for the remote one, if you set the scheme to http or ionic it will work, but might have some other problems.

@allanevargas
Copy link

@jcesarmobile I've got this all set up which is why it works for my Android version. It does work for the iOS but once the app has been ran once but it shouldn't have to work like that. It is still an issue for iOS on WKWebView.

From what I have gathered upon researching this is that this issue has been around for at least a couple of years now and Apple has not added a fix for it and I don't think there will be any fixes either. Some people have created cordova/ionic plugins to allow the cookies to work for WKWebView but this only works for iOS 11+ I believe. An alternative is to this is to switch back to UIWebView which isn't really ideal but it does work.

@jcesarmobile
Copy link
Member

I’ve closed it because there is another issue open (#22)

@lucky3491
Copy link

this plugin is working for me https://github.com/lucky3491/cordova-plugin-wkwebview-inject-cookie

@juliannehalversen
Copy link

this plugin is working for me https://github.com/lucky3491/cordova-plugin-wkwebview-inject-cookie

I am building an app with Ionic and Angular and would like to use your plugin but am having issues. When I install the plugin and try to import it, it's not available to use. Is there something I'm missing here?
Screen Shot 2020-05-05 at 1 54 27 PM

@rsgone
Copy link

rsgone commented May 14, 2020

@juliannehalversen simply declare a normal variable as follows:

declare var wkWebView: any;

@dmitriygoncharenko
Copy link

Are there any updates?

@juliannehalversen
Copy link

Are there any updates?

Here is the link to what I did to fix it: lucky3491/cordova-plugin-wkwebview-inject-cookie#1 (comment)

@rafaellop
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants