Last active
September 7, 2017 18:05
-
-
Save jslnriot/0d6bd5989d9b2eb540135abdc7bfe6dd to your computer and use it in GitHub Desktop.
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
const express = require('express'); | |
// Passport | |
const passport = require('passport'); | |
const GoogleStrategy = require('passport-google-oauth20').Strategy; | |
const keys = require('./config/keys'); | |
const app = express(); | |
// Creates a new instance of the GoogleStrategy | |
// In the constructor tell it how to handle this | |
// Client ID and Client Secret | |
// callbackURL - string is the route that the user | |
// is sent to after they grant permission to our app | |
passport.use( | |
new GoogleStrategy( | |
{ | |
clientID: keys.googleClientID, | |
clientSecret: keys.googleClientSecret, | |
callbackURL: '/auth/google/callback', | |
proxy: true | |
}, | |
(accessToken, refreshToken, profile, done) => { | |
// Take identifying user information and save to db | |
console.log('access token', accessToken); | |
console.log('refresh token', refreshToken); | |
console.log('profile', profile); | |
} | |
) | |
); | |
// Route handler for passport flow | |
// Internally GoogleStrategy has a string of 'google' we can use as the first argument | |
// of passport.authenticate | |
app.get( | |
'/auth/google', | |
passport.authenticate('google', { | |
scope: ['profile', 'email'] | |
}) | |
); | |
// When the user hits this route they have the auth code | |
app.get( | |
'/auth/google/callback', | |
passport.authenticate('google') | |
); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment