-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from andela/ft-soial-auth-#167727629
feature(social Oauth):add social media login route
- Loading branch information
Showing
18 changed files
with
714 additions
and
100 deletions.
There are no files selected for viewing
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,59 @@ | ||
import passport from 'passport'; | ||
import { Strategy as GoogleStrategy } from 'passport-google-oauth20'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
const FacebookStrategy = require('passport-facebook').Strategy; | ||
|
||
const { | ||
GOOGLE_CLIENT_ID, | ||
GOOGLE_CLIENT_SECRET, | ||
FACEBOOK_CLIENT_ID, | ||
FACEBOOK_CLIENT_SECRET, | ||
FACEBOOK_AUTH_CALLBACK_URL, | ||
GOOGLE_AUTH_CALLBACK_URL, | ||
} = process.env; | ||
|
||
/** | ||
* creates a user token | ||
* @param {string} accessToken - contains id, role email | ||
* @param {string} requestToken - | ||
* @param {string} profile - user profile | ||
* @param {string} done - user profile | ||
* @return {object} - user profile | ||
*/ | ||
export const passportCb = (accessToken, requestToken, profile, done) => done( | ||
null, profile | ||
); | ||
|
||
const setupPassport = () => { | ||
passport.use( | ||
new GoogleStrategy({ | ||
callbackURL: GOOGLE_AUTH_CALLBACK_URL, | ||
clientID: GOOGLE_CLIENT_ID, | ||
clientSecret: GOOGLE_CLIENT_SECRET | ||
}, passportCb) | ||
); | ||
passport.use( | ||
new FacebookStrategy({ | ||
callbackURL: FACEBOOK_AUTH_CALLBACK_URL, | ||
clientID: FACEBOOK_CLIENT_ID, | ||
clientSecret: FACEBOOK_CLIENT_SECRET, | ||
profileFields: [ | ||
'id', 'email', 'gender', 'link', 'locale', | ||
'name', 'timezone', 'updated_time', 'verified' | ||
], | ||
}, passportCb) | ||
); | ||
}; | ||
|
||
passport.serializeUser((user, cb) => { | ||
cb(null, user); | ||
}); | ||
|
||
passport.deserializeUser((obj, cb) => { | ||
cb(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
Oops, something went wrong.