From 89a90b8e86525b3510710c22a70f698d184d1462 Mon Sep 17 00:00:00 2001 From: PieterGit <6500826+PieterGit@users.noreply.github.com> Date: Wed, 1 Jan 2020 19:15:29 +0100 Subject: [PATCH] Fix cgm with share2 via nightscout with tokenbased authentication with oref 0.7.x (regression) (#1341) * re-enable cgm inflow of share2 with token based authentication nightscout * syntax Co-authored-by: Scott Leibrand --- bin/oref0-get-ns-entries.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/oref0-get-ns-entries.js b/bin/oref0-get-ns-entries.js index 08bb4b6d5..48f5379bf 100755 --- a/bin/oref0-get-ns-entries.js +++ b/bin/oref0-get-ns-entries.js @@ -64,7 +64,7 @@ if (!module.parent) { process.exit(1); } - if (apisecret.length != 40) { + if (apisecret != null && !apisecret.startsWith("token=") && apisecret.length != 40) { var shasum = crypto.createHash('sha1'); shasum.update(apisecret); apisecret = shasum.digest('hex'); @@ -155,15 +155,20 @@ if (!module.parent) { function loadFromNightscoutWithDate(lastDate, glucosedata) { - var headers = { - 'api-secret': apisecret - }; + // append the token secret to the end of the ns url, or add it to the headers if token based authentication is not used + var headers = {} ; + var tokenAuth = ""; + if (apisecret.startsWith("token=")) { + tokenAuth = "&" + apisecret; + } else { + headers = { 'api-secret': apisecret }; + } if (!_.isNil(lastDate)) { headers["If-Modified-Since"] = lastDate.toISOString(); } - var uri = nsurl + '/api/v1/entries/sgv.json?count=' + records; + var uri = nsurl + '/api/v1/entries/sgv.json?count=' + records + tokenAuth; var options = { uri: uri , json: true