Created
August 22, 2019 13:36
-
-
Save gemanor/d41da5bba1c87298d022093926c81c18 to your computer and use it in GitHub Desktop.
Passport.js file for social login demo
This file contains hidden or 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
| // Import all the | |
| const passport = require('passport'); | |
| const GitHubStrategy = require('passport-github').Strategy; | |
| const LinkedInStrategy = require('passport-linkedin-oauth2').Strategy; | |
| const GoogleStrategy = require('passport-google-oauth20').Strategy; | |
| const TwitterStrategy = require('passport-twitter').Strategy; | |
| const Auth0Strategy = require('passport-auth0').Strategy; | |
| module.exports = (app) => { | |
| passport.use(new GitHubStrategy({ | |
| clientID: process.env['GITHUB_CLIENT_ID'], | |
| clientSecret: process.env['GITHUB_SECRET'], | |
| callbackURL: 'http://localhost:3001/auth/github/callback' | |
| }, (accessToken, refreshToken, profile, done) => done(null, profile))); | |
| passport.use(new LinkedInStrategy({ | |
| clientID: process.env['LINKEDIN_CLIENT_ID'], | |
| clientSecret: process.env['LINKEDIN_SECRET'], | |
| callbackURL: 'http://localhost:3001/auth/linkedin/callback', | |
| scope: ['r_emailaddress', 'r_liteprofile', 'w_member_social'], | |
| }, (accessToken, refreshToken, profile, done) => done(null, profile))); | |
| passport.use(new GoogleStrategy({ | |
| clientID: process.env['GOOGLE_CLIENT_ID'], | |
| clientSecret: process.env['GOOGLE_CLIENT_SECRET'], | |
| callbackURL: 'http://localhost:3001/auth/google/callback', | |
| scope: ['email', 'profile'], | |
| }, (accessToken, refreshToken, profile, done) => done(null, profile))) | |
| passport.use(new TwitterStrategy({ | |
| consumerKey: process.env['TWITTER_CONSUMER_KEY'], | |
| consumerSecret: process.env['TWITTER_CONSUMER_SECRET'], | |
| callbackURL: "http://localhost:3001/auth/twitter/callback", | |
| }, (accessToken, refreshToken, profile, done) => done(null, profile))); | |
| passport.use(new Auth0Strategy({ | |
| clientID: process.env['AUTH0_CONSUMER_KEY'], | |
| clientSecret: process.env['AUTH0_CONSUMER_SECRET'], | |
| domain: process.env['AUTH0_DOMAIN'], | |
| callbackURL: "http://localhost:3001/auth/auth0/callback", | |
| }, (accessToken, refreshToken, profile, done) => done(null, profile))); | |
| passport.serializeUser((user, done) => done(null, user)); | |
| passport.deserializeUser((user, done) => done(null, user)); | |
| app.use(passport.initialize()); | |
| app.use(passport.session()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment