locked
Storing Cookies

    Question

  • As I discovered here, when I make a call to a server to ask for authentication in the form of a cookie, the cookie in the response is handled automatically by the underlying metro framework.

    However, this means I don't have access to the cookie and, therefore, cannot store it when the app is suspended for later use. How are we supposed to store cookie information in the metro framework, so a user doesn't have to log in every time the app is opened, or the system is restarted?

    All help is greatly appreciated and I always accept an answer!


    • Edited by sddhhanover Thursday, August 23, 2012 12:14 AM
    Thursday, August 23, 2012 12:14 AM

Answers

  • You cannot given your current situation.  Something would need to change on the server side to allow this.

    -Jeff


    Jeff Sanders (MSFT)

    • Marked as answer by sddhhanover Wednesday, August 29, 2012 10:57 PM
    Tuesday, August 28, 2012 6:57 PM
    Moderator

All replies

  • You cannot directly manipulate cookies.  If the cookie from the server is marked so it is not stored, it will not be stored and your user will have to log in again (just like a browser would).  If it does not have this restriction then it will be submitted with the next request when you resume.

    You may be able to use the AuthenticationBroker in your situation.  Take a look at these resources:

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh750287.aspx

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh750286.aspx

    http://msdn.microsoft.com/en-us/library/windows/apps/hh465281.aspx

    http://code.msdn.microsoft.com/windowsapps/Web-Authentication-d0485122

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, August 23, 2012 4:37 PM
    Moderator
  • WebAuthenticationBroker does not suit my purpose, since logging in is just an API call for me. But then how would I implement a "remember me" checkbox, like a browser would?
    • Edited by sddhhanover Sunday, August 26, 2012 1:27 PM
    Sunday, August 26, 2012 1:26 PM
  • You cannot given your current situation.  Something would need to change on the server side to allow this.

    -Jeff


    Jeff Sanders (MSFT)

    • Marked as answer by sddhhanover Wednesday, August 29, 2012 10:57 PM
    Tuesday, August 28, 2012 6:57 PM
    Moderator
  • and if you don't have access to the server side?

    for example: Google Music

    Trying to make an App for Windows 8 and i need to read a cookie to get a variable (called "XT") that it's used in the already logged in requests (fetch playlist, fetch song info). Google sends this cookie when you log in, then the google music client side creates requests based on that XT variable (among other vars).

    practicaly i'm stuck after doing the login, being unable to get my google vars for further server request.

    Monday, September 10, 2012 7:35 PM
  • If the server is setting cookies correctly, after logon and you make your next request the XT cookie should be sent for you automatically.


    Jeff Sanders (MSFT)

    Tuesday, September 25, 2012 2:21 PM
    Moderator
  • You don't get it.

    I make a request then I get response with Set-Cookie header (containing the XT cookie).

    On the next request i need to put the value of THAT cookie in the POST header/line/whatever. Example:

    POST https://play.google.com/music/service/loadalltracks?u=0&xt=" + encodeURIComponent(XT_COOKIE) + " HTTP/1.0\r\n

    got it ?

    Tuesday, September 25, 2012 8:33 PM
  • Hi Gabriel,

    You are incorrect, I do get it.  You cannot do this.  This is not standard cookie behavior and there is no mechanism in XHR to do this.  This is not allowed by the W3C RFC that defines the behavior of XHR.  If your server obeys and conforms to standard cookie behavior, then XHR will send any valid cookies automatically (again according to W3C RFCs).  Check with google support and see if they have an API or way to get the behavior you want.  You may be able to bypass the cookie requirement or find from them how to call this another way.

    -Jeff


    Jeff Sanders (MSFT)


    Wednesday, September 26, 2012 12:18 PM
    Moderator
  • google is not going to make changes just for my sake and there is no official API.

    instead I made a class that uses the  Windows.Networking.Sockets.StreamSocket() object, that handles my requests from now on.

    I suggest anybody reading this thread to do the same if access to reading cookies / advanced requests handling is needed.

    Friday, September 28, 2012 9:20 PM