Skip to content

Commit

Permalink
Merge pull request #18 from andela/bg-fix-social-login-159069548
Browse files Browse the repository at this point in the history
#159069548 User should be able to signIn/signOut using the existing auth URL
  • Loading branch information
Oreofeoluwapo Ralph Olutola committed Jul 19, 2018
2 parents 49fd54f + 37c3e93 commit e7419b5
Show file tree
Hide file tree
Showing 26 changed files with 244 additions and 341 deletions.
11 changes: 10 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
MONGOHQ_URL_TEST=<Test database url>
MONGODB_URI=<Development database url>
SECRET_KEY=<Secret key for JWT>
GMAIL_PASSWORD=<password is pinned at slack channel>
GMAIL_PASSWORD=<password is pinned at slack channel>
FB_CLIENT_ID=<pinned to slack et-team channel>
FB_CLIENT_SECRET=<pinned to slack et-team channel>
FB_CALLBACK_URL=<pinned to slack et-team channel>
GOOGLE_CLIENT_ID=<pinned to slack et-team channel>
GOOGLE_CLIENT_SECRET=<pinned to slack et-team channel>
GOOGLE_CALLBACK_URL=<pinned to slack et-team channel>
TWITTER_CUSTOMER_KEY=<pinned to slack et-team channel>
TWITTER_CUSTOMER_SECRET=<pinned to slack et-team channel>
TWITTER_CALLBACK_URL=<pinned to slack et-team channel>
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

27 changes: 27 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@
},
"SECRET_KEY": {
"required": true
},
"FB_CLIENT_ID": {
"required": true
},
"FB_CLIENT_SECRET": {
"required": true
},
"FB_CALLBACK_URL": {
"required": true
},
"GOOGLE_CLIENT_ID": {
"required": true
},
"GOOGLE_CLIENT_SECRET": {
"required": true
},
"GOOGLE_CALLBACK_URL": {
"required": true
},
"TWITTER_CUSTOMER_KEY": {
"required": true
},
"TWITTER_CUSTOMER_SECRET": {
"required": true
},
"TWITTER_CALLBACK_URL": {
"required": true
}
},
"formation": {
Expand Down
20 changes: 17 additions & 3 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,23 @@ const authCallback = (req, res) => {
* @param {req} req carries request payload
* @param {res} res handles response status code and messages
* @returns {res} a status code and data
* @description this function is called with an Oauth 2 authentication is complete
* the authentication returns a user which info is sent to the client through the url.
*/
const signin = (req, res) => {
if (!req.user) {
res.redirect('/#!/signin');
} else {
res.redirect('/#!/app');
const { user } = req;
// Create a token using the user data
const token = Tokenizer(user);

// the token and the user info to the client through the url
const url = `/#!/auth?${token}---${user.name}---${user._id}---${user.tour}`;
res.redirect(url);
}
};


/**
* @param {object} req - request object provided by express
* @param {object} res - response object provided by express
Expand Down Expand Up @@ -130,6 +137,13 @@ const fetchProfile = (req, res, next) => handleFetchProfile(req.user._id)
});


/**
* @param {object} req - request object from OAUTH callback
* @param {object} res - request object provided by express
* @description This action generates a token after a successful oauth login and sends the token
* the client to be used for subsequent requests.
*/

/**
* @param {object} req - request object provided by express
* @param {object} res - response object provided by express
Expand Down Expand Up @@ -387,5 +401,5 @@ export default {
handleSignUp,
avatars,
findUsers,
invite,
invite
};
3 changes: 1 addition & 2 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mongoose from 'mongoose';
import bcrypt from 'bcryptjs';

const { Schema } = mongoose;
const authTypes = ['github', 'twitter', 'facebook', 'google'];
const authTypes = ['twitter', 'facebook', 'google'];

/**
* User Schema
Expand All @@ -22,7 +22,6 @@ const UserSchema = new Schema({
hashed_password: String,
facebook: {},
twitter: {},
github: {},
google: {}
});

Expand Down
42 changes: 0 additions & 42 deletions app/views/includes/foot2.jade

This file was deleted.

33 changes: 0 additions & 33 deletions app/views/includes/head2.jade

This file was deleted.

22 changes: 0 additions & 22 deletions app/views/users/auth.jade

This file was deleted.

13 changes: 0 additions & 13 deletions app/views/users/choose-avatar.jade

This file was deleted.

20 changes: 0 additions & 20 deletions app/views/users/signin.jade

This file was deleted.

69 changes: 0 additions & 69 deletions app/views/users/signup.jade

This file was deleted.

23 changes: 9 additions & 14 deletions config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@ module.exports = {
port: process.env.PORT,
MONGOHQ_URL: process.env.MONGODB_URI,
facebook: {
clientID: 'APP_ID',
clientSecret: 'APP_SECRET',
callbackURL: 'http://cardsforhumanity.com:3000/auth/facebook/callback'
clientID: process.env.FB_CLIENT_ID,
clientSecret: process.env.FB_CLIENT_SECRET,
callbackURL: process.env.FB_CALLBACK_URL
},
twitter: {
clientID: 'CONSUMER_KEY',
clientSecret: 'CONSUMER_SECRET',
callbackURL: 'http://cardsforhumanity.com:3000/auth/twitter/callback'
},
github: {
clientID: 'APP_ID',
clientSecret: 'APP_SECRET',
callbackURL: 'http://cardsforhumanity.com:3000/auth/github/callback'
clientID: process.env.TWITTER_CUSTOMER_KEY,
clientSecret: process.env.TWITTER_CUSTOMER_SECRET,
callbackURL: process.env.TWITTER_CALLBACK_URL
},
google: {
clientID: 'APP_ID',
clientSecret: 'APP_SECRET',
callbackURL: 'http://cardsforhumanity.com:3000/auth/google/callback'
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.GOOGLE_CALLBACK_URL
}
};
23 changes: 9 additions & 14 deletions config/env/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@ module.exports = {
},
MONGOHQ_URL: process.env.MONGODB_URI,
facebook: {
clientID: 'APP_ID',
clientSecret: 'APP_SECRET',
callbackURL: 'http://cfh.io/auth/facebook/callback'
clientID: process.env.FB_CLIENT_ID,
clientSecret: process.env.FB_CLIENT_SECRET,
callbackURL: process.env.FB_CALLBACK_URL
},
twitter: {
clientID: 'CONSUMER_KEY',
clientSecret: 'CONSUMER_SECRET',
callbackURL: 'http://cfh.io/auth/twitter/callback'
},
github: {
clientID: 'APP_ID',
clientSecret: 'APP_SECRET',
callbackURL: 'http://cfh.io/auth/github/callback'
clientID: process.env.TWITTER_CUSTOMER_KEY,
clientSecret: process.env.TWITTER_CUSTOMER_SECRET,
callbackURL: process.env.TWITTER_CALLBACK_URL
},
google: {
clientID: 'APP_ID',
clientSecret: 'APP_SECRET',
callbackURL: 'http://cfh.io/auth/google/callback'
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.GOOGLE_CALLBACK_URL
}
};
Loading

0 comments on commit e7419b5

Please sign in to comment.