diff options
author | Deepak Kodihalli <dkodihal@in.ibm.com> | 2017-11-10 05:03:45 -0600 |
---|---|---|
committer | Deepak Kodihalli <dkodihal@in.ibm.com> | 2017-11-19 23:25:43 -0600 |
commit | 8cc1a034b264d8771648840f3bc57f07ccad72fa (patch) | |
tree | 1812d9b76776638241323e98197d4d967b9bfb33 | |
parent | 765c2c8ba8c3d88f4d00bd769516809c88e57674 (diff) | |
download | phosphor-rest-server-8cc1a034b264d8771648840f3bc57f07ccad72fa.tar.gz phosphor-rest-server-8cc1a034b264d8771648840f3bc57f07ccad72fa.zip |
websocket client_simple example: add login code
Change-Id: Iff44de21e71508d81f7c5bfbe24b5f317fff000d
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
-rw-r--r-- | module/obmc/wsgi/examples/websockets/client_simple.html | 14 |
1 files 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://<BMC IP>/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: ["<username>", "<password>"]})); // 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://<BMC IP>" + value; xhr.open("GET", url, true); xhr.setRequestHeader("Content-type", "application/json"); |