Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use cookies in a Cordova application?

I have been building an android app using Ionic. At this point, I am under the impression that Cordova applications do not save or send the cookies that are served from a REST API server. If I run the application with the 'ionic serve' command I can see that my session and CSRF cookies are sent with my AJAX requests. However, when I run the code with the 'ionic emulate' command it does not appear that either are sent to my server.

I have seen some articles and threads that talk about using the setAcceptThirdPartyCookies() method in the class that extends CordovaActivity, but that hasn't worked for me.

I have tried using $httpProvider.defaults.withCredentials = true in my angular module config to no avail.

I have tried using ngCookies, but that doesn't appear to get a handle on the cookies from my API server either.

I just want to know once and for all if using cookies in a Cordova application is possible or not. If it isn't I will go with a token based approach. It would be nice to be able to use the same security configuration for the mobile app and web app though.

like image 872
chriaass Avatar asked Jun 30 '15 13:06

chriaass


People also ask

What browser does Cordova use?

1. I figured out that Cordova is not using the Chrome App as browser. Instead it is using the browser integrated in the "Android System WebView" app, which is updatable in Google Play Store. Actually it is Chrome, but a different version from the Chrome App.

Is Cordova outdated?

Replying to the question of whether Cordova is deprecated or still relevant, we want to start with the allegation that Apache Cordova is still alive. The concrete markers comprise new updates with improvements and fixes. Cordova Android 10.1. 1 was released in September 2021.

Is Cordova secure?

Since a Cordova application is built from HTML and JavaScript assets that get packaged in a native container, you should not consider your code to be secure.

Does ionic use cookies?

We may use cookies and similar technologies to operate and improve the Ionic Services, as well as to simplify our interaction with you.


2 Answers

You can't use cookies, you should use localStorage

Browsers provide a convenient module for storing data in a simple key <-> value fashion called localStorage. This is an object on window that we can get and set String values easily

See this for details

like image 63
Matteo Basso Avatar answered Sep 25 '22 02:09

Matteo Basso


No, you can't. I have also tried to use cookies in one of my applications, but it didn't work because the cookies are disabled in the new version of Android. I solved this problem by using the HTML5 localStorage API.

like image 29
Stanimir Dimitrov Avatar answered Sep 23 '22 02:09

Stanimir Dimitrov