mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 01:10:31 +01:00
beginning google integration
This commit is contained in:
@@ -17,6 +17,10 @@ var config = {
|
||||
"twitter": {
|
||||
"key": '',
|
||||
"secret": ''
|
||||
},
|
||||
"google": {
|
||||
"id": '',
|
||||
"secret": ''
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"passport": "0.1.16",
|
||||
"passport-local": "0.1.6",
|
||||
"passport-twitter": "0.1.4",
|
||||
"passport-google-oauth": "0.1.5",
|
||||
"less-middleware": "0.1.11"
|
||||
},
|
||||
"devDependencies": {},
|
||||
|
||||
@@ -165,7 +165,23 @@ footer.footer {
|
||||
padding: 0;
|
||||
|
||||
li {
|
||||
vertical-align: top;
|
||||
.inline-block;
|
||||
.pointer;
|
||||
|
||||
&.google {
|
||||
width: 202px;
|
||||
height: 32px;
|
||||
background: transparent;
|
||||
background-image: url('../images/google_login.png');
|
||||
|
||||
&:hover {
|
||||
background-position-x: -265px;
|
||||
}
|
||||
|
||||
&:active {
|
||||
background-position-x: -535px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
public/images/google_login.png
Normal file
BIN
public/images/google_login.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.4 KiB |
@@ -16,6 +16,7 @@
|
||||
<h4>Alternative Logins</h4>
|
||||
<ul class="alt-logins">
|
||||
<li><a href="/auth/twitter"><img src="/images/twitter_login.png" /></a></li>
|
||||
<li class="google"></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -9,6 +9,7 @@ var express = require('express'),
|
||||
passport = require('passport'),
|
||||
passportLocal = require('passport-local').Strategy,
|
||||
passportTwitter = require('passport-twitter').Strategy,
|
||||
passportGoogle = require('passport-google-oauth').OAuth2Strategy,
|
||||
login_strategies = [];
|
||||
|
||||
passport.use(new passportLocal(function(user, password, next) {
|
||||
@@ -22,7 +23,7 @@ if (config.twitter.key.length > 0 && config.twitter.secret.length > 0) {
|
||||
passport.use(new passportTwitter({
|
||||
consumerKey: config.twitter.key,
|
||||
consumerSecret: config.twitter.secret,
|
||||
callbackURL: config.url + "auth/twitter/callback"
|
||||
callbackURL: config.url + 'auth/twitter/callback'
|
||||
}, function(token, tokenSecret, profile, done) {
|
||||
global.modules.user.loginViaTwitter(profile.id, profile.username, function(err, user) {
|
||||
if (err) { return done(err); }
|
||||
@@ -33,6 +34,19 @@ if (config.twitter.key.length > 0 && config.twitter.secret.length > 0) {
|
||||
login_strategies.push('twitter');
|
||||
}
|
||||
|
||||
if (config.google.id.length > 0 && config.google.secret.length > 0) {
|
||||
passport.use(new passportGoogle({
|
||||
clientID: config.google.id,
|
||||
clientSecret: config.google.secret,
|
||||
callbackURL: config.url + 'auth/google/callback'
|
||||
}, function(accessToken, refreshToken, profile, done) {
|
||||
console.log(accessToken, refreshToken, profile);
|
||||
done('hardcode fail');
|
||||
}))
|
||||
|
||||
login_strategies.push('google');
|
||||
}
|
||||
|
||||
passport.serializeUser(function(user, done) {
|
||||
done(null, user.uid);
|
||||
});
|
||||
@@ -161,6 +175,15 @@ passport.deserializeUser(function(uid, done) {
|
||||
}));
|
||||
}
|
||||
|
||||
if (login_strategies.indexOf('google') !== -1) {
|
||||
app.get('/auth/google', passport.authenticate('google', { scope: {} }));
|
||||
|
||||
app.get('/auth/google/callback', passport.authenticate('google', {
|
||||
successRedirect: '/',
|
||||
failureRedirect: '/login'
|
||||
}));
|
||||
}
|
||||
|
||||
app.get('/reset/:code', function(req, res) {
|
||||
res.send(templates['header'] + templates['reset_code'].parse({ reset_code: req.params.code }) + templates['footer']);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user