-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(socialAuth): Setup social authentication
- setup passport for facebook authentication - setup passport for google authentication [#164139772]
- Loading branch information
Black Developa
committed
Apr 3, 2019
1 parent
3320b68
commit 2104031
Showing
9 changed files
with
983 additions
and
1,391 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import passport from 'passport'; | ||
import { Strategy as FacebookStrategy } from 'passport-facebook'; | ||
import { Strategy as GoogleStrategy } from 'passport-google-oauth20'; | ||
import env from './env-config'; | ||
import { socialAuthCallback } from '../utils/helpers'; | ||
|
||
const setUpPassport = () => { | ||
passport.use( | ||
new GoogleStrategy( | ||
{ | ||
clientID: env.GOOGLE_CLIENT_ID, | ||
clientSecret: env.GOOGLE_CLIENT_SECRET, | ||
callbackURL: 'http://localhost:3000/api/auth/google/callback' | ||
}, | ||
socialAuthCallback | ||
) | ||
); | ||
|
||
passport.use( | ||
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.serializeUser((user, done) => { | ||
done(null, user); | ||
}); | ||
|
||
passport.deserializeUser((obj, done) => { | ||
done(null, obj); | ||
}); | ||
}; | ||
|
||
export default setUpPassport; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,5 @@ | ||
import dotenv from 'dotenv'; | ||
import 'dotenv/config'; | ||
|
||
dotenv.config(); | ||
const { env } = process; | ||
const { | ||
DATABASE_URL, | ||
NODE_ENV, | ||
PORT, | ||
SECRET, | ||
SENDGRID_KEY, | ||
ADMIN_EMAIL, | ||
SITE_NAME, | ||
HEROKU_APP_NAME, | ||
UI_CLIENT_HOST, | ||
API_SERVER_HOST, | ||
AUTH_TOKEN_EXPIRY, | ||
VERIFICATION_LINK_EXPIRY | ||
} = env; | ||
|
||
export default { | ||
DATABASE_URL, | ||
NODE_ENV, | ||
PORT, | ||
SECRET, | ||
SENDGRID_KEY, | ||
ADMIN_EMAIL, | ||
SITE_NAME, | ||
HEROKU_APP_NAME, | ||
UI_CLIENT_HOST, | ||
API_SERVER_HOST, | ||
AUTH_TOKEN_EXPIRY, | ||
VERIFICATION_LINK_EXPIRY | ||
}; | ||
export default env; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Router } from 'express'; | ||
import passport from 'passport'; | ||
import debug from 'debug'; | ||
|
||
const router = new Router(); | ||
|
||
const logger = debug('vale-ah::socialAuth: '); | ||
|
||
router.get( | ||
'/login/facebook', | ||
passport.authenticate('facebook', { scope: ['email'] }) | ||
); | ||
router.get( | ||
'/facebook/callback', | ||
passport.authenticate('facebook'), | ||
(req, res) => { | ||
logger(req.user); | ||
res.redirect('/'); | ||
} | ||
); | ||
|
||
router.get( | ||
'/login/google', | ||
passport.authenticate('google', { scope: ['profile', 'email'] }) | ||
); | ||
router.get('/google/callback', passport.authenticate('google'), (req, res) => { | ||
logger(req.user); | ||
res.redirect('/'); | ||
}); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters