From e86cb69d021d336516586577d6794d1c48b1f3be Mon Sep 17 00:00:00 2001 From: Claudio Chimera Date: Mon, 18 Oct 2021 17:46:28 +0200 Subject: [PATCH] test page checks state --- alexa/alexa-adapter.js | 10 ++++++---- alexa/html/test.html | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/alexa/alexa-adapter.js b/alexa/alexa-adapter.js index 5871104..efc0c8c 100644 --- a/alexa/alexa-adapter.js +++ b/alexa/alexa-adapter.js @@ -195,6 +195,7 @@ module.exports = function (RED) { node.error("setup Tokens load error " + err); }) + node.UnregisterUrl(); if (node.http_port.trim()) { if (node.config.verbose) node._debug("setup listen port " + node.http_port); node.app = express(); @@ -210,7 +211,6 @@ module.exports = function (RED) { } else { if (node.config.verbose) node._debug("Use the Node-RED port"); } - node.UnregisterUrl(); let urlencodedParser = express.urlencoded({ extended: false }) let jsonParser = express.json() @@ -287,11 +287,13 @@ module.exports = function (RED) { shutdown(removed, done) { var node = this; if (node.config.verbose) node._debug("(on-close)"); - if (node.app != node.http_server) { + node.UnregisterUrl(); + if (node.http_server != (RED.httpNode || RED.httpAdmin)) { if (node.config.verbose) node._debug("Stopping server"); - node.http_server.stop(); + node.http_server.stop(function(err, grace) { + if (node.config.verbose) node._debug("Server stopped " + grace + " " + err); + }); } - node.UnregisterUrl(); if (removed) { // this node has been deleted if (node.config.verbose) node._debug("shutdown: removed"); diff --git a/alexa/html/test.html b/alexa/html/test.html index ce9d718..3155b8c 100644 --- a/alexa/html/test.html +++ b/alexa/html/test.html @@ -62,7 +62,7 @@ "&state=" + encodeURIComponent(state) + "&redirect_uri=" + encodeURIComponent(redirect_uri), success: function (data) { - test_success('oauth_get', 'OK '); + test_success('oauth_get', 'OK'); if (go_on) test_oauth_post(url); }, error: function (xhr, status) { @@ -101,8 +101,13 @@ success: function (data, status, xhr1) { const params = new URLSearchParams(xhr.responseURL); const code = params.get('code'); + const return_state = params.get('state'); if (code) { - test_success('oauth_post', 'OK '); + if (state === return_state) { + test_success('oauth_post', 'OK'); + } else { + test_success('oauth_post', 'STATE Error'); + } test_token_post(url, code); } else { test_success('oauth_post', 'ERROR invalid login and password'); @@ -125,7 +130,7 @@ success: function (data) { let access_token = data['access_token']; if (access_token) { - test_success('token_post', 'OK '); + test_success('token_post', 'OK'); test_smarthome_post(url, access_token); } else { test_success('token_post', 'ERROR: missin access token '); @@ -159,7 +164,7 @@ }), headers: { authorization: "Bearer " + code }, success: function (data) { - test_success('smarthome_post', 'OK '); + test_success('smarthome_post', 'OK'); test_success('smarthome_result', JSON.stringify(data)); }, error: function (xhr, status) {