Skip to content

Commit

Permalink
Fix cgm with share2 via nightscout with tokenbased authentication wit…
Browse files Browse the repository at this point in the history
…h oref 0.7.x (regression) (#1341)

* re-enable cgm inflow of share2 with token based authentication nightscout

* syntax

Co-authored-by: Scott Leibrand <scottleibrand@gmail.com>
  • Loading branch information
PieterGit and scottleibrand committed Jan 1, 2020
1 parent c16a841 commit 89a90b8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions bin/oref0-get-ns-entries.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 89a90b8

Please sign in to comment.