Namespace scope org for 'Web Server' OAuth2. Set db on token refresh save. Fix the...
authorBen Thompson <ben@xtuple.com>
Wed, 24 Jul 2013 16:40:16 +0000 (12:40 -0400)
committerBen Thompson <ben@xtuple.com>
Wed, 24 Jul 2013 16:40:16 +0000 (12:40 -0400)
node-datasource/main.js
node-datasource/oauth2/oauth2.js
node-datasource/routes/auth.js

index b1cd4f0..0b6c132 100755 (executable)
@@ -206,7 +206,12 @@ var conditionalExpressSession = function (req, res, next) {
 
   // REST API endpoints start with "/api" in their path.
   // The 'assets' folder and login page are sessionless.
-  if ((/^api/i).test(req.path.split("/")[2]) || (/^\/assets/i).test(req.path) || req.path === "/") {
+  if ((/^api/i).test(req.path.split("/")[2]) ||
+    (/^\/assets/i).test(req.path) ||
+    req.path === "/" ||
+    req.path === "/favicon.ico"
+    ) {
+
     next();
   } else {
     if (req.path === "/login") {
@@ -252,7 +257,12 @@ var conditionalPassportSession = function (req, res, next) {
 
   // REST API endpoints start with "/api" in their path.
   // The 'assets' folder and login page are sessionless.
-  if ((/^api/i).test(req.path.split("/")[2]) || (/^\/assets/i).test(req.path) || req.path === "/") {
+  if ((/^api/i).test(req.path.split("/")[2]) ||
+    (/^\/assets/i).test(req.path) ||
+    req.path === "/" ||
+    req.path === "/favicon.ico"
+    ) {
+
     next();
   } else {
     // Instead of doing app.use(passport.session())
@@ -296,6 +306,8 @@ require('./oauth2/passport');
  * Setup HTTP routes and handlers.
  */
 var that = this;
+
+app.use(express.favicon(__dirname + '/views/login/assets/favicon.ico'));
 app.get('/:org/debug', function (req, res, next) {
   "use strict";
   if (!req.session.passport.user) {
index 9f93d8f..9605907 100644 (file)
@@ -257,6 +257,8 @@ server.exchange(oauth2orize.exchange.refreshToken(function (client, refreshToken
       return done && done(err);\r
     };\r
 \r
+    saveOptions.database = client.get("organization");\r
+\r
     // Set model values and save.\r
     token.set("state", "Token Refreshed");\r
     token.set("accessToken", accesshash);\r
@@ -439,7 +441,7 @@ exports.authorization = [
 \r
     // Get the org from the scope URI e.g. 'dev' from: 'https://mobile.xtuple.com/auth/dev'\r
     scope = url.parse(scope[0], true);\r
-    var scopeOrg = scope.path.match(/\/auth\/(.*)/)[1] || null;\r
+    var scopeOrg = scope.path.split("/")[1] || null;\r
 \r
     db.clients.findByClientId(clientID, scopeOrg, function (err, client) {\r
       if (err) { return done(err); }\r
index 0f26db4..a19715b 100644 (file)
@@ -187,7 +187,7 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
 
           // Get the org from the scope URI e.g. 'dev' from: 'https://mobile.xtuple.com/auth/dev'
           scope = url.parse(value, true);
-          org = scope.path.match(/\/auth\/(.*)/)[1] || null;
+          org = scope.path.split("/")[1] || null;
 
           // TODO - Still need more work to support userinfo calls.
           // See node-datasource/oauth2/oauth2.js authorization.