locked
WebSocket authentication with Cookie

    Question

  • Hi all,

    I'm trying to connect to a websocket web service. For the service to allow me to connect to it, I need to pass a cookie with an ID and a GUID when connecting.

    I've managed to retrieve the cookie, but I have no idea how I can pass the cookie through the MessageWebSocket.

    Any ideas?

    Project: Universal App, Windows Phone 8.1, C#

    Sunday, September 21, 2014 12:15 AM

Answers

  • You are correct.

    I found a "work around". Since cookie info is basically sent as part of the header of a connection, we can do this:

    Code:

    webSocket.SetRequestHeader("Cookie", "CookieName" + "=" + "CookieValue");

    So that solved it for me at least!

    • Marked as answer by Cato L Monday, September 22, 2014 8:09 AM
    Monday, September 22, 2014 8:09 AM

All replies

  • Hi Cato,

    From your description, I assume you want to make a secure WebSocket connection to a web service. Unfortunately, I cannot find anything about using cookie in WebSocket authentication from here. http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.messagewebsocket.aspx.

    In order to secure connections between client and server when using WebSocket, an easy way to work around is to provide authentication credentials to web service. MessageWebSocket class has a property called MessageWebSocketControl, we can use ServerCredential property to set a request header. See more information from How to secure connections and MessageWebSocketControl.ServerCredential.

    If I misunderstand, please feel free to let me know.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 22, 2014 6:56 AM
    Moderator
  • You are correct.

    I found a "work around". Since cookie info is basically sent as part of the header of a connection, we can do this:

    Code:

    webSocket.SetRequestHeader("Cookie", "CookieName" + "=" + "CookieValue");

    So that solved it for me at least!

    • Marked as answer by Cato L Monday, September 22, 2014 8:09 AM
    Monday, September 22, 2014 8:09 AM