From 8963f77e9bfdb913f6fa50ed256133b5a9f0d2ee Mon Sep 17 00:00:00 2001 From: Manuel Silva Date: Fri, 8 Feb 2013 23:00:44 +1100 Subject: [PATCH] Add google login --- app/helpers/passport/actions.js | 17 ++++++++++++----- app/helpers/passport/strategies.js | 10 ++++++++++ app/views/ejs/main/index.html.ejs | 2 +- app/views/ejs/main/login.html.ejs | 5 +++++ app/views/handlebars/main/index.html.hbs | 2 +- app/views/handlebars/main/login.html.hbs | 5 +++++ app/views/jade/main/index.html.jade | 2 +- app/views/jade/main/login.html.jade | 2 ++ app/views/mustache/main/index.html.ms | 2 +- app/views/mustache/main/login.html.ms | 5 +++++ config/router.js | 2 ++ config/secrets.json.template | 4 ++++ package.json | 1 + 13 files changed, 50 insertions(+), 9 deletions(-) diff --git a/app/helpers/passport/actions.js b/app/helpers/passport/actions.js index a5f6eb7..f2bc10e 100644 --- a/app/helpers/passport/actions.js +++ b/app/helpers/passport/actions.js @@ -10,6 +10,7 @@ var SUPPORTED_SERVICES = [ 'twitter' , 'facebook' , 'yammer' + , 'google' ]; passport.use(new LocalStrategy(function(username, password, done) { @@ -41,13 +42,19 @@ SUPPORTED_SERVICES.forEach(function (item) { callbackURL: geddy.config.fullHostname + '/auth/' + item + '/callback' } - , Strategy = require('passport-' + item).Strategy; + , Strategy = require('passport-' + item).Strategy + , verifyCallback = function(token, tokenSecret, profile, done) { + done(null, profile); + }; geddy.mixin(config, geddy.config.passport[item]); - passport.use(new Strategy(config, - function(token, tokenSecret, profile, done) { - done(null, profile); - })); + + if(item=='google'){ + verifyCallback = function(identity, profile, done) { + done(null, profile); + }; + } + passport.use(new Strategy(config, verifyCallback)); }); var actions = new (function () { diff --git a/app/helpers/passport/strategies.js b/app/helpers/passport/strategies.js index b0c63e2..006832d 100644 --- a/app/helpers/passport/strategies.js +++ b/app/helpers/passport/strategies.js @@ -43,5 +43,15 @@ module.exports = { return userData; } } +, google: { + name: 'Google' + , keyField: 'id' + , parseProfile: function (profile) { + var userData = { + givenName: profile.name.givenName + , familyName: profile.name.familyName + }; + return userData; + } }; diff --git a/app/views/ejs/main/index.html.ejs b/app/views/ejs/main/index.html.ejs index 4e3c125..7e56710 100644 --- a/app/views/ejs/main/index.html.ejs +++ b/app/views/ejs/main/index.html.ejs @@ -10,6 +10,6 @@

Hello, stranger

You're not authenticated with this app.

<%- linkTo('Click here to create a user account.', addUserPath) %>

-

<%- linkTo('Click here to log in with Facebook or Twitter.', loginPath) %>

+

<%- linkTo('Click here to log in with Facebook, Twitter or Google.', loginPath) %>

<% } %> diff --git a/app/views/ejs/main/login.html.ejs b/app/views/ejs/main/login.html.ejs index 1a66925..e7d52ac 100644 --- a/app/views/ejs/main/login.html.ejs +++ b/app/views/ejs/main/login.html.ejs @@ -35,5 +35,10 @@ href="<%= geddy.config.fullHostname %><%= facebookPath %>"> Log in with Facebook +   + + Log in with Google +

diff --git a/app/views/handlebars/main/index.html.hbs b/app/views/handlebars/main/index.html.hbs index d38179c..1105aba 100644 --- a/app/views/handlebars/main/index.html.hbs +++ b/app/views/handlebars/main/index.html.hbs @@ -13,6 +13,6 @@

Hello, stranger

You're not authenticated with this app.

{{{ linkTo 'Click here to create a user account.' addUserPath }}}

-

{{{ linkTo 'Click here to log in with Facebook or Twitter.' loginPath }}}

+

{{{ linkTo 'Click here to log in with Facebook, Twitter or Google.' loginPath }}}

{{/if}} diff --git a/app/views/handlebars/main/login.html.hbs b/app/views/handlebars/main/login.html.hbs index 3bfcf5a..468b3e7 100644 --- a/app/views/handlebars/main/login.html.hbs +++ b/app/views/handlebars/main/login.html.hbs @@ -35,5 +35,10 @@ href="{{ geddy.config.fullHostname }}{{ facebookPath }}%>"> Log in with Facebook +   + + Log in with Google +

diff --git a/app/views/jade/main/index.html.jade b/app/views/jade/main/index.html.jade index 09d784a..85a0809 100644 --- a/app/views/jade/main/index.html.jade +++ b/app/views/jade/main/index.html.jade @@ -14,4 +14,4 @@ p != linkTo('Click here to create a user account.', addUserPath) p - != linkTo('Click here to log in with Facebook or Twitter.', loginPath) + != linkTo('Click here to log in with Facebook, Twitter or Google.', loginPath) diff --git a/app/views/jade/main/login.html.jade b/app/views/jade/main/login.html.jade index a2cc832..6205dfd 100644 --- a/app/views/jade/main/login.html.jade +++ b/app/views/jade/main/login.html.jade @@ -24,6 +24,8 @@ a.btn-auth.btn-twitter.large(href="#{geddy.config.fullHostname}#{twitterPath}") Log in with Twitter |   a.btn-auth.btn-facebook.large(href="#{geddy.config.fullHostname}#{facebookPath}") Log in with Facebook + |   + a.btn-auth.btn-google.large(href="#{geddy.config.fullHostname}#{googlePath}") Log in with Google diff --git a/app/views/mustache/main/index.html.ms b/app/views/mustache/main/index.html.ms index d38179c..1105aba 100644 --- a/app/views/mustache/main/index.html.ms +++ b/app/views/mustache/main/index.html.ms @@ -13,6 +13,6 @@

Hello, stranger

You're not authenticated with this app.

{{{ linkTo 'Click here to create a user account.' addUserPath }}}

-

{{{ linkTo 'Click here to log in with Facebook or Twitter.' loginPath }}}

+

{{{ linkTo 'Click here to log in with Facebook, Twitter or Google.' loginPath }}}

{{/if}} diff --git a/app/views/mustache/main/login.html.ms b/app/views/mustache/main/login.html.ms index 3bfcf5a..468b3e7 100644 --- a/app/views/mustache/main/login.html.ms +++ b/app/views/mustache/main/login.html.ms @@ -35,5 +35,10 @@ href="{{ geddy.config.fullHostname }}{{ facebookPath }}%>"> Log in with Facebook +   + + Log in with Google +

diff --git a/config/router.js b/config/router.js index 446020d..8824c75 100644 --- a/config/router.js +++ b/config/router.js @@ -29,6 +29,8 @@ router.get('/auth/facebook').to('Auth.facebook'); router.get('/auth/facebook/callback').to('Auth.facebookCallback'); router.get('/auth/yammer').to('Auth.yammer'); router.get('/auth/yammer/callback').to('Auth.yammerCallback'); +router.get('/auth/google').to('Auth.google'); +router.get('/auth/google/callback').to('Auth.googleCallback'); // Basic routes // router.match('/moving/pictures/:id', 'GET').to('Moving.pictures'); diff --git a/config/secrets.json.template b/config/secrets.json.template index 35cc4a9..8a3d8bf 100644 --- a/config/secrets.json.template +++ b/config/secrets.json.template @@ -12,6 +12,10 @@ "yammer":{ "clientID": "XXXXX", "clientSecret": "XXXXX" + }, + "google": { + "returnURL": "XXXXX", + "realm": "XXXXX" } } } diff --git a/package.json b/package.json index 0bd6128..0aa7f7e 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "passport-twitter": "0.1.x", "passport-facebook": "0.1.x", "passport-yammer": "0.1.x", + "passport-google": "0.2.x", "bcrypt": "0.7.x" }, "main": "./lib/passport",