Browse Source

Merge branch 'staging'

* staging:
  CD-8 CD-10 #resolve Clean up config.sample.js
  CD-7 #resolve Adds better error catching to endpoint validation
  CD-6 #resolve Adds endpoint validation when adding a new endpoint from wizard

# Conflicts:
#	src/config.sample.js
George Vrancianu 8 years ago
parent
commit
315725dd1c
4 changed files with 1 additions and 158 deletions
  1. 0 35
      src/config.sample.js
  2. 0 93
      src/core/passport.js
  3. 1 29
      src/server.js
  4. 0 1
      src/stores/MigrationStore/MigrationStore.js

+ 0 - 35
src/config.sample.js

@@ -25,18 +25,6 @@ export const defaultDomain = "default";
 
 // Number of instances in wizard Migrate VMs step
 export const itemsPerPage = 6;
-/*
--- Network mocked data
- id - random
- name - source network
- migrateNetwork - target network, null if new network
- selected - true
-*/
-export const networkMock = [
-  { id: "net1", name: "VM Network", migrateNetwork: "management", selected: true} ,
-]
-// Target networks to show in dropdown
-export const targetNetworkMock = ["internal-coriolis-2", "coriolis-twenty", "management"]
 export const securityGroups = ["testgroup"]
 
 export const servicesUrl = {
@@ -104,26 +92,3 @@ export const migrationSteps = [
     component: "WizardSummary"
   }
 ]
-
-export const auth = {
-
-  jwt: { secret: process.env.JWT_SECRET || 'Coriolis' },
-
-  // https://developers.facebook.com/
-  facebook: {
-    id: process.env.FACEBOOK_APP_ID || '186244551745631',
-    secret: process.env.FACEBOOK_APP_SECRET || 'a970ae3240ab4b9b8aae0f9f0661c6fc',
-  },
-
-  // https://cloud.google.com/console/project
-  google: {
-    id: process.env.GOOGLE_CLIENT_ID || '251410730550-ahcg0ou5mgfhl8hlui1urru7jn5s12km.apps.googleusercontent.com',
-    secret: process.env.GOOGLE_CLIENT_SECRET || 'Y8yR9yZAhm9jQ8FKAL8QIEcd',
-  },
-
-  // https://apps.twitter.com/
-  twitter: {
-    key: process.env.TWITTER_CONSUMER_KEY || 'Ie20AZvLJI2lQD5Dsgxgjauns',
-    secret: process.env.TWITTER_CONSUMER_SECRET || 'KTZ6cxoKnEakQCeSpZlaUCJWGAlTEBJj0y2EMkUBujA7zWSvaQ',
-  },
-};

+ 0 - 93
src/core/passport.js

@@ -14,98 +14,5 @@
  */
 
 import passport from 'passport';
-import { Strategy as FacebookStrategy } from 'passport-facebook';
-import db from './db';
-import { auth as config } from '../config';
-
-/**
- * Sign in with Facebook.
- */
-passport.use(new FacebookStrategy({
-  clientID: config.facebook.id,
-  clientSecret: config.facebook.secret,
-  callbackURL: '/login/facebook/return',
-  profileFields: ['name', 'email', 'link', 'locale', 'timezone'],
-  passReqToCallback: true,
-}, (req, accessToken, refreshToken, profile, done) => {
-  const loginName = 'facebook';
-  db.connect(async ({ query }) => {
-    if (req.user) {
-      let result = await query(
-        'SELECT 1 FROM user_login WHERE name = $1 AND key = $2',
-        loginName, profile.id
-      );
-      if (result.rowCount) {
-        // There is already a Facebook account that belongs to you.
-        // Sign in with that account or delete it, then link it with your current account.
-        done();
-      } else {
-        await query(`
-          INSERT INTO user_account (id, email) SELECT $1, $2::character
-            WHERE NOT EXISTS (SELECT 1 FROM user_account WHERE id = $1);`,
-          req.user.id, profile._json.email);
-        await query(`
-          INSERT INTO user_login (user_id, name, key) VALUES ($1, 'facebook', $2);`,
-          req.user.id, profile.id);
-        await query(`
-          INSERT INTO user_claim (user_id, type, value) VALUES
-            ($1, 'urn:facebook:access_token', $3);`,
-          req.user.id, profile.id);
-        await query(`
-          INSERT INTO user_profile (user_id) SELECT $1
-            WHERE NOT EXISTS (SELECT 1 FROM user_profile WHERE user_id = $1);`,
-          req.user.id);
-        await query(`
-          UPDATE user_profile SET
-            display_name = COALESCE(NULLIF(display_name, ''), $2),
-            gender       = COALESCE(NULLIF(gender, ''), $3),
-            picture      = COALESCE(NULLIF(picture, ''), $4),
-          WHERE user_id = $1;`,
-          req.user.id, profile.displayName, profile._json.gender,
-          `https://graph.facebook.com/${profile.id}/picture?type=large`);
-        result = await query(`
-          SELECT id, email FROM user_account WHERE id = $1;`,
-          req.user.id);
-        done(null, result.rows[0]);
-      }
-    } else {
-      let result = await query(`
-        SELECT u.id, u.email FROM user_account AS u
-          LEFT JOIN user_login AS l ON l.user_id = u.id
-        WHERE l.name = $1 AND l.key = $2`, loginName, profile.id);
-      if (result.rowCount) {
-        done(null, result.rows[0]);
-      } else {
-        result = await query('SELECT 1 FROM user_account WHERE email = $1', profile._json.email);
-        if (result.rowCount) {
-          // There is already an account using this email address. Sign in to
-          // that account and link it with Facebook manually from Account Settings.
-          done(null);
-        } else {
-          result = await query(`
-            INSERT INTO user_account (email) VALUES ($1) RETURNING (id)`,
-            profile._json.email
-          );
-          const userId = result.rows[0].id;
-          await query(`
-            INSERT INTO user_login (user_id, name, key) VALUES ($1, 'facebook', $2)`,
-            userId, profile.id);
-          await query(`
-            INSERT INTO user_claim (user_id, type, value) VALUES
-              ($1, 'urn:facebook:access_token', $2);`,
-            userId, accessToken);
-          await query(`
-            INSERT INTO user_profile (user_id, display_name, gender, picture)
-            VALUES ($1, $2, $3, $4);`,
-            userId, profile.displayName, profile._json.gender,
-            `https://graph.facebook.com/${profile.id}/picture?type=large`
-          );
-          result = await query('SELECT id, email FROM user_account WHERE id = $1;', userId);
-          done(null, result.rows[0]);
-        }
-      }
-    }
-  }).catch(done);
-}));
 
 export default passport;

+ 1 - 29
src/server.js

@@ -21,14 +21,11 @@ import path from 'path';
 import express from 'express';
 import cookieParser from 'cookie-parser';
 import bodyParser from 'body-parser';
-import expressJwt from 'express-jwt';
-import jwt from 'jsonwebtoken';
 import ReactDOM from 'react-dom/server';
 import PrettyError from 'pretty-error';
-import passport from './core/passport';
 import Router from './routes';
 import assets from './assets';
-import { port, auth, analytics } from './config';
+import { port, analytics } from './config';
 
 const server = global.server = express();
 
@@ -47,31 +44,6 @@ server.use(cookieParser());
 server.use(bodyParser.urlencoded({ extended: true }));
 server.use(bodyParser.json());
 
-//
-// Authentication
-// -----------------------------------------------------------------------------
-server.use(expressJwt({
-  secret: auth.jwt.secret,
-  credentialsRequired: false,
-  /* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
-  getToken: req => req.cookies.id_token,
-  /* jscs:enable requireCamelCaseOrUpperCaseIdentifiers */
-}));
-server.use(passport.initialize());
-
-server.get('/login/facebook',
-  passport.authenticate('facebook', { scope: ['email', 'user_location'], session: false })
-);
-server.get('/login/facebook/return',
-  passport.authenticate('facebook', { failureRedirect: '/login', session: false }),
-  (req, res) => {
-    const expiresIn = 60 * 60 * 24 * 180; // 180 days
-    const token = jwt.sign(req.user, auth.jwt.secret, { expiresIn });
-    res.cookie('id_token', token, { maxAge: 1000 * expiresIn, httpOnly: true });
-    res.redirect('/');
-  }
-);
-
 server.post('/federation', async (req, res) => {
   let token = req.body.token
   if (token) {

+ 0 - 1
src/stores/MigrationStore/MigrationStore.js

@@ -20,7 +20,6 @@
 
 import Reflux from 'reflux';
 import MigrationActions from '../../actions/MigrationActions';
-import {networkMock, targetNetworkMock} from '../../config';
 import moment from 'moment';
 
 class MigrationStore extends Reflux.Store