Skip to content

Commit

Permalink
Merge 27cd402 into e59f1b1
Browse files Browse the repository at this point in the history
  • Loading branch information
Black Developa committed Apr 10, 2019
2 parents e59f1b1 + 27cd402 commit a75f4f6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 50 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A Social platform for the creative at heart",
"main": "index.js",
"scripts": {
"start": "cross-env NODE_ENV=production node dist/index.js",
"start": "node dist/index.js",
"heroku-postbuild": "npm run initdb && npm run build",
"build": "babel server -d dist --source-maps",
"test": "cross-env NODE_ENV=test npm run initdb && DEBUG=vale-ah* nyc --reporter=text --reporter=html mocha --timeout=20000 --recursive --exit",
Expand Down
65 changes: 29 additions & 36 deletions server/config/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,48 @@ import { Strategy as FacebookStrategy } from 'passport-facebook';
import { Strategy as GoogleStrategy } from 'passport-google-oauth20';
import { Strategy as TwitterStrategy } from 'passport-twitter';
import env from './env-config';
import { MockStrategy } from '../../test/mockStrategy';
import { socialAuthCallback } from '../utils/helpers';
import db from '../models';

const { User } = db;

const setUpPassport = () => {
passport.use(
env.NODE_ENV === 'test'
? new MockStrategy('google', socialAuthCallback)
: new GoogleStrategy(
{
clientID: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
callbackURL: 'http://localhost:3000/api/auth/google/callback'
},
socialAuthCallback
)
new GoogleStrategy(
{
clientID: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
callbackURL: 'http://localhost:3000/api/auth/google/callback'
},
socialAuthCallback
)
);

passport.use(
env.NODE_ENV === 'test'
? new MockStrategy('facebook', socialAuthCallback)
: new FacebookStrategy(
{
clientID: env.FACEBOOK_CLIENT_ID,
clientSecret: env.FACEBOOK_CLIENT_SECRET,
callbackURL: 'http://localhost:3000/api/auth/facebook/callback',
profileFields: ['id', 'name', 'displayName', 'email', 'photos']
},
socialAuthCallback
)
new FacebookStrategy(
{
clientID: env.FACEBOOK_CLIENT_ID,
clientSecret: env.FACEBOOK_CLIENT_SECRET,
callbackURL: 'http://localhost:3000/api/auth/facebook/callback',
profileFields: ['id', 'name', 'displayName', 'email', 'photos']
},
socialAuthCallback
)
);

passport.use(
env.NODE_ENV === 'test'
? new MockStrategy('twitter', socialAuthCallback)
: new TwitterStrategy(
{
consumerKey: env.TWITTER_CONSUMER_KEY,
consumerSecret: env.TWITTER_CONSUMER_SECRET,
callbackURL: 'http://localhost:3000/api/auth/twitter/callback',
userProfileURL:
'https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true',
includeEmail: true,
includeName: true
},
socialAuthCallback
)
new TwitterStrategy(
{
consumerKey: env.TWITTER_CONSUMER_KEY,
consumerSecret: env.TWITTER_CONSUMER_SECRET,
callbackURL: 'http://localhost:3000/api/auth/twitter/callback',
userProfileURL:
'https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true',
includeEmail: true,
includeName: true
},
socialAuthCallback
)
);

passport.serializeUser((user, done) => {
Expand Down
10 changes: 0 additions & 10 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import cors from 'cors';
import morgan from 'morgan';
import debug from 'debug';
import passport from 'passport';
import session from 'express-session';
import passportSetUp from './config/auth';
import env from './config/env-config';
import routes from './routes/index';
Expand All @@ -22,15 +21,6 @@ app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.use(
session({
secret: env.SECRET,
cookie: { maxAge: 60000 },
resave: false,
saveUninitialized: false
})
);

routes(app);
app.listen(env.PORT, () => {
logger(`Listening on port ${env.PORT}`);
Expand Down
19 changes: 16 additions & 3 deletions test/mockStrategy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
/* eslint-disable no-underscore-dangle */
import Passport from 'passport';
import { randomSocialUser } from './fixtures';
import passport from 'passport';
import faker from 'faker';
import { socialAuthCallback } from '../server/utils/helpers';

const randomSocialUser = {
id: faker.random.number(),
displayName: faker.random.alphaNumeric(10),
emails: [{ value: faker.internet.email() }],
photos: [{ value: faker.image.image() }]
};

// }
/**
* MockStrategy Class
*/
class MockStrategy extends Passport.Strategy {
class MockStrategy extends passport.Strategy {
/**
* @param {*} name
* @param {*} callback
Expand All @@ -28,4 +37,8 @@ class MockStrategy extends Passport.Strategy {
}
}

passport.use(new MockStrategy('google', socialAuthCallback));
passport.use(new MockStrategy('facebook', socialAuthCallback));
passport.use(new MockStrategy('twitter', socialAuthCallback));

export { MockStrategy, randomSocialUser };

0 comments on commit a75f4f6

Please sign in to comment.