Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Google OAuth 2.0 Passport strategy. #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion keys.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
, "clientSecret": ""
, "callbackURL": "http://local.host:3000/auth/github/callback"
}

, "google": {
"clientID": ""
, "clientSecret": ""
, "callbackURL": "http://local.host:3000/auth/google/callback"
}
}
6 changes: 4 additions & 2 deletions lib/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ const setPicture = (user, profile) => {
*/

const generateStrategy = provider => {
// Geneate routes
// Generate routes
const options = provider === 'google' ? { scope: ['profile'] } : {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably require 'email' scope in addition to profile, because we are trusting the user's email input without verification.

app.get(`/auth/${provider}`, saveRedirect, passport.authenticate(provider));
app.get(`/auth/${provider}/callback`, passport.authenticate(provider, { failureRedirect: '/' }), redirectSubdomain);

// Require provider own module
// TODO: Figure out how to use ES2015 syntax instead of requires
const Strategy = require(`passport-${provider}`).Strategy;
const strategyName = provider === 'google' ? 'passport-google-oauth20' : `passport-${provider}`;
const Strategy = require(strategyName).Strategy;

passport.use(new Strategy(keys[provider], async (token, tokenSecret, profile, done) => {
let user = await User.findOne({provider_id: profile.id, provider: provider}).exec();
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"passport": "0.2.2",
"passport-facebook": "2.0.0",
"passport-github": "0.1.5",
"passport-google-oauth20": "^1.0.0",
"passport-http": "^0.3.0",
"passport-meetup": "0.1.2",
"passport-twitter": "1.0.3",
Expand Down