Skip to content

Commit

Permalink
test page checks state
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio Chimera authored and Claudio Chimera committed Oct 18, 2021
1 parent 181d31f commit e86cb69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
10 changes: 6 additions & 4 deletions alexa/alexa-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()

Expand Down Expand Up @@ -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");
Expand Down
13 changes: 9 additions & 4 deletions alexa/html/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand All @@ -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 ');
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e86cb69

Please sign in to comment.