I wish to create an application using node-webkit which does the simple job to open a remote web application. The web application has some cookie based authentication. Considering that the user has signed-in successfully, how can the required cookies be retained, so that the next time the application runs, the user will be authenticated?
You can get auth cookies using this instructions: https://github.com/nwjs/nw.js/wiki/window#windowcookies
Save it with prefered method: https://github.com/nwjs/nw.js/wiki/Save-persistent-data-in-app
On next start just check that record exists, and set cookies with method from 1.
Should be something like this:
var gui = require('nw.gui');
var win = gui.Window.get();
function login() {
var opts = {};
if(localStorage.auth) {
opts.cookies: [
'Auth': localStorage.auth
];
}
someRequest.get(opts, function(result) {
if(result)
localStorage.auth = win.cookies.get('auth');
});
}
As of 2018, NW.js retains cookies and other persistent browser data by default. These are stored in %LOCALAPPDATA%/name-in-manifest/
in Windows or equivalent depending on OS. Nothing is required from the application itself, you do not have to persist cookie data manually in local storage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With