--- /dev/null
+const PORT = 8080
+
+const HTTP_OK = 200;
+const HTTP_BAD_REQUEST = 400;
+const HTTP_INTERNAL_ERROR = 500;
+
+var express = require('express');
+var app = express();
+var bodyParser = require('body-parser');
+
+//var sqlite3 = require('sqlite3').verbose();
+//var db = new sqlite3.Database('firmware.db');
+
+app.use(express.static('public'));
+app.use(bodyParser.urlencoded({ extended: false }));
+
+// this enables desktop to accept redirect_uri from browser
+var server = app.listen(PORT, function () {
+ var port = server.address().port;
+ console.log("OAuth broker listening at http://127.0.0.1:%s", port)
+})
+
+app.post('/auth_response', function(req, res) {
+ var code = req.query.code;
+ var id = req.query.id;
+
+ console.log("auth code: [", code, "]");
+ console.log("id: [", id, "]");
+
+ /* DB write */
+
+ res.sendStatus(200);
+})
+
+app.get('/auth_code', function(req, res) {
+ var id = req.query.id;
+ console.log("id: [", id, "]");
+
+ /* DB read */
+
+ res.sendStatus(200);
+})
+
+
--- /dev/null
+{
+ "name": "oauth-broker",
+ "version": "0.0.1",
+ "main": "oauth_broker.js",
+ "dependencies": {
+ "express": "4.14.x",
+ "body-parser": "1.16.x",
+ "sqlite3": "3.1.x",
+ "request" : "2.81.x"
+ }
+}
--- /dev/null
+const OAUTH_BROKER_ADDR = "http://127.0.0.1:8080";
+const PORT = 8000;
+const REQ_ID = "0101231234";
+
+const HTTP_OK = 200;
+const HTTP_BAD_REQUEST = 400;
+const HTTP_INTERNAL_ERROR = 500;
+
+var express = require('express');
+var app = express();
+var bodyParser = require('body-parser');
+var request = require('request');
+
+app.use(express.static('public'));
+app.use(bodyParser.urlencoded({ extended: false }));
+
+// this enables desktop to accept redirect_uri from browser
+var server = app.listen(PORT, function () {
+ var port = server.address().port;
+ console.log("OAuth redirect_uri handler listening at http://127.0.0.1:%s", port)
+})
+
+app.get('/oauth_callback', function(req, res) {
+ console.log("auth code: [", req.query.code, "]");
+ var http = require('http');
+
+ var jsonBody={};
+ jsonBody.id = REQ_ID;
+ jsonBody.code = req.query.code;
+
+ console.log("jsonBody:", jsonBody);
+
+ var postHeaders = {
+ 'Content-Type' : 'application/json',
+ 'Content-Length' : Buffer.byteLength(JSON.stringify(jsonBody), 'utf8')
+ };
+
+ var query = "id=" + REQ_ID + "&" + "code="+req.query.code;
+ var options = {
+ host: '127.0.0.1',
+ port: '8080',
+ path: '/auth_response?' + query,
+ method: 'POST' ,
+ headers : postHeaders
+ };
+
+ console.info(options);
+
+ var http_req = http.request(options, function(res) {
+ console.log('STATUS:' + res.statusCode);
+ //console.log('HEADERS:' + JSON.stringify(res.headers));
+ res.setEncoding('utf8');
+ res.on('data', function (chunk) {
+ console.log('BODY: ' + chunk);
+ });
+ });
+ http_req.write(JSON.stringify(jsonBody)); //'{"id":"12334", "code":req.query.code}');
+ http_req.end();
+ http_req.on('error', function(e) {
+ console.error(e);
+ });
+
+ var html = "<!DOCTYPE html>\n<html>\n <head>\n </head>\n <body>\n <h1>CODE [" + req.query.code +"]</h1>\n </body>\n</html>";
+ res.send(html);
+})
--- /dev/null
+{
+ "name": "oauth-broker-client",
+ "version": "0.0.1",
+ "main": "oauth_redirect_uri_handler.js",
+ "dependencies": {
+ "express": "4.14.x",
+ "body-parser": "1.16.x",
+ "request" : "2.81.x"
+ }
+}
--- /dev/null
+<!DOCTYPE html>
+<html>
+<body>
+<p>Click the button to send req_auth to GITHUB.</p>
+
+<button onclick="reqAuthToGithub()">GITHUB</button>
+<!-- this page acts as client app in mobile phone, and will be replaced -->
+<script>
+function reqAuthToGithub() {
+ window.open("https://github.com/login/oauth/authorize?client_id=e6bd5594e38b7f268af1&redirect_uri=http://127.0.0.1:8000/oauth_callback");
+
+}
+</script>
+
+</body>
+</html>
+
+
+++ /dev/null
-<!DOCTYPE html>
-<html>
-<body>
-<p>Click the button to send req_auth to GITHUB.</p>
-
-<button onclick="reqAuthToGithub()">GITHUB</button>
-<!-- this page acts as client app in mobile phone, and will be replaced -->
-<script>
-function reqAuthToGithub() {
- window.open("https://github.com/login/oauth/authorize?client_id=e6bd5594e38b7f268af1&redirect_uri=http://127.0.0.1:8000/oauth_callback");
-
-}
-</script>
-
-</body>
-</html>
-
-