npm_login_test
Version:
143 lines (116 loc) • 3.37 kB
Plain Text
const app_Initialize=()=> {
return passport.initialize()
}
exports.app_Initialize = app_Initialize
const app_Session=()=> {
return passport.session()
}
exports.app_Session = app_Session
module.exports.socialMedia_Config = (social_config) => {
var { GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET,
FACEBOOK_APP_ID,
FACEBOOK_APP_SECRET,
LINKEDIN_CLIENT_ID,
LINKEDIN_CLIENT_SECRET } = social_config
if ((!GOOGLE_CLIENT_ID) && (!GOOGLE_CLIENT_SECRET)) {
GOOGLE_CLIENT_ID = " ",
GOOGLE_CLIENT_SECRET = " "
}
if ((!FACEBOOK_APP_ID) && (!FACEBOOK_APP_SECRET)) {
FACEBOOK_APP_ID = " ",
FACEBOOK_APP_SECRET = " "
}
if ((!LINKEDIN_CLIENT_ID) && (!LINKEDIN_CLIENT_SECRET)) {
LINKEDIN_CLIENT_ID = " ",
LINKEDIN_CLIENT_SECRET = " "
}
passport.use(new GoogleStrategy(
{
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "/auth/google/callback",
profileFields: ["email"],
enableProof: true,
},
function (accessToken, refreshToken, profile, done) {
done(null, profile);
}
)
);
passport.use(
new FacebookStrategy(
{
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: "/auth/facebook/callback",
},
function (accessToken, refreshToken, profile, done) {
done(null, profile);
}
)
);
passport.use(
new LinkedInStrategy(
{
clientID: LINKEDIN_CLIENT_ID,
clientSecret: LINKEDIN_CLIENT_SECRET,
callbackURL: "/auth/linkedin/callback",
scope: ['r_emailaddress', 'r_liteprofile']
},
async function (accessToken, refreshToken, profile, done) {
done(null, profile);
}
)
);
}
passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser((user, done) => {
done(null, user);
});
module.exports = passport
module.exports.googleData = (req, res) => {
passport.authenticate('google', { scope: ['profile', 'email'] })
(req, res)
}
module.exports.facebookData = (req, res) => {
passport.authenticate("facebook", { scope: "email" })
(req, res)
}
module.exports.linkedinData = (req, res) => {
passport.authenticate("linkedin", { scope: ['r_emailaddress', 'r_liteprofile'] })
(req, res)
}
var LINK = {
Google_url: "",
Facebook_url: "",
Linkedin_url: ""
}
module.exports.clientURL_config = (URL_config) => {
const { CLIENT_Google_URL,
CLIENT_Facebook_URL,
CLIENT_Linkedin_URL } = URL_config
LINK.Google_url = CLIENT_Google_URL;
LINK.Facebook_url = CLIENT_Facebook_URL;
LINK.Linkedin_url = CLIENT_Linkedin_URL;
}
module.exports.googleCallback = (req, res) => {
passport.authenticate("google", {
successRedirect: LINK.Google_url,
failureRedirect: "/login/failed",
})(req, res)
}
module.exports.facebookCallback = (req, res) => {
passport.authenticate("facebook", {
successRedirect: LINK.Facebook_url,
failureRedirect: "/login/failed",
})(req, res)
}
module.exports.linkedinCallback = (req, res) => {
passport.authenticate("linkedin", {
successRedirect: LINK.Linkedin_url,
failureRedirect: "/login/failed",
})(req, res)
}