From 8cc1a034b264d8771648840f3bc57f07ccad72fa Mon Sep 17 00:00:00 2001 From: Deepak Kodihalli Date: Fri, 10 Nov 2017 05:03:45 -0600 Subject: websocket client_simple example: add login code Change-Id: Iff44de21e71508d81f7c5bfbe24b5f317fff000d Signed-off-by: Deepak Kodihalli --- module/obmc/wsgi/examples/websockets/client_simple.html | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/module/obmc/wsgi/examples/websockets/client_simple.html b/module/obmc/wsgi/examples/websockets/client_simple.html index cdc8be5..3a009c4 100644 --- a/module/obmc/wsgi/examples/websockets/client_simple.html +++ b/module/obmc/wsgi/examples/websockets/client_simple.html @@ -10,12 +10,13 @@ // xyz.openbmc_project.Sensor.Value being added, or property changes to // these interfaces. - - // Insert code here to log-on to the BMC. At the moment of writing this - // example, I don't know how to do that in javascript (I had disabled the - // the authorization plug-in in rest_dbus.py to test this example). See - // https://github.com/openbmc/docs/blob/master/rest-api.md for the log-on - // API. + // Login to the BMC. + var xhr = new XMLHttpRequest(); + xhr.open("POST", "https:///login", true); + // Set 'withCredentials' to be able to send back login session cookie. + xhr.withCredentials = true; + xhr.setRequestHeader("Content-type", "application/json"); + xhr.send(JSON.stringify({data: ["", ""]})); // Open a new secure websocket. The rest server on the BMC // only supports the /subscribe route with websockets as of now. @@ -46,6 +47,7 @@ // If the d-bus path is in the response, let's do a GET on // that path. var xhr = new XMLHttpRequest(); + xhr.withCredentials = true; var url = "https://" + value; xhr.open("GET", url, true); xhr.setRequestHeader("Content-type", "application/json"); -- cgit v1.2.1