I have a node js server and an android client. Basically I have two options for authentication: rest api + http basic or sessions. I prefer sessions, because storing user credentials to the memory of a phone doesn't seem like a good idea. Session id is temporary, so storing it would not be a security issue.
I've tried the following approach: On node js I'm using express-session middleware. On client side, session id is stored in variable SID. With every request, cookie "connect.sid=SID" is set. If response contains set-cookie, SID is set to match connect.sid. However, this approach does not work. I could however generate my own id and not use express at all.
Also, I don't understand browser behaviour with express sessions. I'm using https, if that makes any difference. It works fine, but first of all, all requests create 2 operations: one with OPTIONS method and the other with the actual operation. The response to options request returns set-cookie. In actual operation requests, cookie "connect.sid" is set. In every request the id is same BUT each set-cookie returned by the server has a different id and the id sent by the client does not match any of these ids. Could someone explain what's going on?
Authenticating to a server with a mobile application is a very common situation these days. What is the recommended way to handle it (without third parties)?