maintaining session cookies in $http requests

513 views
Skip to first unread message

Gerardo Flores

unread,
Dec 5, 2012, 7:25:38 PM12/5/12
to ang...@googlegroups.com
I'm building a PhoneGap application that is mostly offline but needs to reach out to a server to authenticate users and get data relevant to the user.  CORS is enabled on the server side, and I was able to get the authentication step to complete successfully.  The response to the authentication sets a cookie (
Set-Cookie:
PLAY_SESSION=XxXXX) that I'm supposed to use in subsequent requests. This cookie, however, is not maintained by $http as a browser normally would, and I can't seem to get access to this cookie via javascript so I can manually add it to requests. How should I maintain this cookie across requests? The authentication request is an $http.post where I post credentials. I then later do an $http.get to request a data set for the user.
Message has been deleted

Zerho

unread,
Jan 22, 2013, 4:43:54 AM1/22/13
to ang...@googlegroups.com
did you managed to solve the problem?

Marco Rinck

unread,
Jan 22, 2013, 3:15:44 PM1/22/13
to ang...@googlegroups.com
The catch with CORS and cookies is that your ajax requests need to have the "withCredential" option set in config for $http, like this: 

var config = {
  withCredentials: true
}

$http.get(url, config); 

Additionally the server has to answer pre-flight requests with HTTP-Header "Access-Control-Allow-Credentials: true".

 

Marco 
Reply all
Reply to author
Forward
0 new messages