Skip to content

Commit

Permalink
version bump, log cleanup and base image update after fixing GitHub O…
Browse files Browse the repository at this point in the history
…Auth
  • Loading branch information
suculent committed Nov 8, 2023
1 parent 3e86382 commit 6e3dd1f
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM thinxcloud/base:alpine

LABEL maintainer="Matej Sychra <[email protected]>"
LABEL name="THiNX API" version="1.9.2429"
LABEL name="THiNX API" version="1.9.2451"

ARG DEBIAN_FRONTEND=noninteractive

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM thinxcloud/base:alpine

LABEL maintainer="Matej Sychra <[email protected]>"
LABEL name="THiNX API" version="1.9.2429"
LABEL name="THiNX API" version="1.9.2451"

ARG DEBIAN_FRONTEND=noninteractive

Expand Down
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## HISTORY

6/11/2023 1.9.2429
6/11/2023 1.9.2451

» Updating vulnerable components
» Improving security configuration
Expand Down
2 changes: 1 addition & 1 deletion base
Submodule base updated 2 files
+209 −125 package-lock.json
+3 −4 package.json
5 changes: 2 additions & 3 deletions lib/router.github.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ module.exports = function (app) {
}
}

// added recently, seems to be missing/forgotten or deprecated or compatibility fix for testing or what?
// githubOAuth.addRoutes(app, callback); causes error 500
// configure callbacks for Emitter events

githubOAuth.on('error', (err) => {
console.error('[debug] [oauth] [github] there was a login error', err);
Expand Down Expand Up @@ -230,7 +229,7 @@ module.exports = function (app) {
});
});

callback(); // essentialy useless, why is this here?<
callback(); // async completes the secureGithubCallbacks()
}

// Initial page redirecting to OAuth2 provider
Expand Down
42 changes: 6 additions & 36 deletions lib/thinx/oauth-github.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ module.exports = function (opts) {
var redirectURI = url.format(urlObj);
var emitter = new events.EventEmitter();

// why is this unused?
function addRoutes(router, loginCallback) {
console.log("[debug] emitter.addRoutes called, keep this code even when it looks unreferenced!");
// compatible with flatiron/director
router.get(opts.loginURI, login);
router.get(opts.callbackURI, callback);
if (!loginCallback) return;
emitter.on('error', function (token, err, resp, tokenResp, req) {
loginCallback(err, token, resp, tokenResp, req)
});
emitter.on('token', function (token, resp, tokenResp, req) {
loginCallback(false, token, resp, tokenResp, req)
});
}

function login(req, resp) {
var u = 'https://github.com/login/oauth/authorize'
+ '?client_id=' + opts.githubClient
Expand All @@ -42,7 +27,6 @@ module.exports = function (opts) {
}

function parseResponse(body) {
// 'access_token=gho_XXX&scope=user&token_type=bearer'
const items = body.split("&");
var data = null;
for (item in items) {
Expand All @@ -54,7 +38,6 @@ module.exports = function (opts) {
break;
}
}
console.log("[debug] [oauth-github] body, data ", {body}, {data});
return data;
}

Expand All @@ -78,34 +61,21 @@ module.exports = function (opts) {
const body = await axios.get(u);
console.log("[debug] emitting event token with body", { body });
const data = parseResponse(body.data);

if (data == "bad_verification_code") {
//
}

if (data.indexOf("'gho_") !== -1) {
//
}

const q = url.parse(body.data, true).query;
console.log("[debug] emitting event token with data", { data }, JSON.stringify(q));
if (cb) {
console.log("[debug] cb non-null, calling...");
cb(null, data);
if (data.indexOf("gho_") !== -1) {
emitter.emit('token', data);
if (cb) return cb(null, data);
} else {
console.log("[debug] Invalid GitHub Response:", {body});
}
emitter.emit('token', data);
} catch (e) {
console.log("axios get error:", e);
if (cb) {
return cb(e);
}
if (cb) return cb(e);
emitter.emit('error', null, e);
}
})()
}

emitter.login = login;
emitter.callback = callback;
emitter.addRoutes = addRoutes;
return emitter;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thinx",
"version": "1.9.2429",
"version": "1.9.2451",
"description": "THiNX IoT Device Management API",
"bugs": {
"url": "https://github.com/suculent/thinx-device-api/issues"
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sonar.organization=suculent
sonar.sources=.
sonar.host.url=https://sonarcloud.io

sonar.projectVersion=1.9.2429
sonar.projectVersion=1.9.2451
sonar.sourceEncoding=UTF-8

sonar.junit.reportsPath=reports/
Expand Down

0 comments on commit 6e3dd1f

Please sign in to comment.