Commits

Seb Ruiz committed 031c992

Remove unused oauth request middleware code

Comments (0)

Files changed (4)

 var urls = require('url');
 var _ = require('underscore');
 var fs = require('fs');
-var http = require('request');
 var RSVP = require('rsvp');
 var util = require('util');
 var config = require('./internal/config');

lib/internal/addon-descriptor.js

 var utils = require('./utils');
 
 module.exports = function (addon) {
-    return utils.replaceTokensInJson(utils.loadJSON('atlassian-connect.json'),
-            '%%BASE_URI%%', addon.config.localBaseUrl());
+    return utils.replaceTokensInJson(utils.loadJSON('atlassian-connect.json'), '{{localBaseUrl}}', addon.config.localBaseUrl());
 };

lib/middleware/request.js

 
 module.exports = function (addon) {
 
-    var clientSettings;
-
-    var requestHandlerMiddleware = function (clientKey) {
-        return function (req, res, next) {
-            getClientSettings(clientKey)(req, res, next).then(requestHandler);
-        }
-    };
-
-    var getClientSettings = function (clientKey) {
-        return function (req, res, next) {
-            addon.settings.get('clientInfo', clientKey).then(function (settings) {
-                clientSettings = settings;
-                next();
-            });
-        }
-    };
-
     var requestHandler = function (req, res, next) {
 
         // @todo this is a mess and needs to be rewritten with a clear
                 hostBaseUrl: hostUrl + (req.param('cp') || ''),
                 license: req.param('lic'),
                 timeZone: req.param('tz'),
-                locale: req.param('loc'),
-                clientKey: req.param('oauth_consumer_key')
+                locale: req.param('loc')
             };
             _.extend(req.session, params);
         } else {
         copyCtxParams(req.params, params, 'ctx_');
         copyCtxParams(req.query, params, 'ctx_');
 
-        if (!params.hostBaseUrl && req.headers && req.headers.authorization) {
-            // initial macro requests
-            // parse appId from consumer key & lookup persisted settings
-            // @todo refactor this further to leverage oauth auth header parsing
-            var match = req.headers.authorization.match(/oauth_consumer_key="([^"]+)"/);
-            if (match) {
-                params.clientKey = decodeURIComponent(match[1]);
-                addon.settings.get('clientInfo', params.clientKey).then(
-                        function (appData) {
-                            params.hostBaseUrl = appData && appData.baseUrl;
-                            if (params.hostBaseUrl) {
-                                var url = urls.parse(params.hostBaseUrl);
-                                url.pathname = '';
-                                params.hostUrl = urls.format(url);
-                            }
-                            augmentRequest(params, req, res, next);
-                        },
-                        function () {
-                            addon.logger.error.apply(addon.logger, arguments);
-                            augmentRequest(params, req, res, next);
-                        }
-                );
-            } else {
-                // other pathways still need to continue through the middleware chain
-                augmentRequest(params, req, res, next);
-            }
-        } else {
-            // iframe and ajax requests made after rehydration from the session
-            augmentRequest(params, req, res, next);
-        }
-
+        augmentRequest(params, req, res, next);
     };
 
     function augmentRequest(params, req, res, next) {
         };
         var expectedCanonical = "GET&/path/to/service&first=param&repeated=Parameter%202,parameter%201,parameter%202&zee_last=param";
 
-        var canonical = jwt._createCanonicalRequest(req);
+        var canonical = jwt.createCanonicalRequest(req);
         assert.equal(canonical, expectedCanonical);
         done();
     });
         };
         var expectedCanonical = "GET&/hello-world&cp=%2Fjira&lic=none&loc=en-US&tz=Australia%2FSydney&user_id=&user_key=&xdm_c=channel-servlet-hello-world&xdm_e=http%3A%2F%2Fstorm%3A2990&xdm_p=1";
 
-        var canonical = jwt._createCanonicalRequest(req);
+        var canonical = jwt.createCanonicalRequest(req);
         assert.equal(canonical, expectedCanonical);
         done();
     });