Add support of google signin
This commit is contained in:
parent
900141daff
commit
6405bb5056
10 changed files with 47 additions and 8 deletions
|
@ -121,7 +121,7 @@ Third-party integration api key settings
|
||||||
---
|
---
|
||||||
| service | file path | description |
|
| service | file path | description |
|
||||||
| ------- | --------- | ----------- |
|
| ------- | --------- | ----------- |
|
||||||
| facebook, twitter, github, gitlab, dropbox | `config.json` | for signin |
|
| facebook, twitter, github, gitlab, dropbox, google | `config.json` | for signin |
|
||||||
| imgur | `config.json` | for image upload |
|
| imgur | `config.json` | for image upload |
|
||||||
| google drive, dropbox | `public/js/common.js` | for export and import |
|
| google drive, dropbox | `public/js/common.js` | for export and import |
|
||||||
|
|
||||||
|
|
13
app.js
13
app.js
|
@ -317,6 +317,19 @@ if (config.dropbox) {
|
||||||
res.redirect(config.serverurl);
|
res.redirect(config.serverurl);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
//google auth
|
||||||
|
if (config.google) {
|
||||||
|
app.get('/auth/google',
|
||||||
|
passport.authenticate('google', { scope: ['profile'] }));
|
||||||
|
//google auth callback
|
||||||
|
app.get('/auth/google/callback',
|
||||||
|
passport.authenticate('google', {
|
||||||
|
failureRedirect: config.serverurl
|
||||||
|
}),
|
||||||
|
function (req, res) {
|
||||||
|
res.redirect(config.serverurl);
|
||||||
|
});
|
||||||
|
}
|
||||||
//logout
|
//logout
|
||||||
app.get('/logout', function (req, res) {
|
app.get('/logout', function (req, res) {
|
||||||
if (config.debug && req.isAuthenticated())
|
if (config.debug && req.isAuthenticated())
|
||||||
|
|
|
@ -41,6 +41,10 @@
|
||||||
"clientID": "change this",
|
"clientID": "change this",
|
||||||
"clientSecret": "change this"
|
"clientSecret": "change this"
|
||||||
},
|
},
|
||||||
|
"google": {
|
||||||
|
"clientID": "change this",
|
||||||
|
"clientSecret": "change this"
|
||||||
|
},
|
||||||
"imgur": {
|
"imgur": {
|
||||||
"clientID": "change this"
|
"clientID": "change this"
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ var TwitterStrategy = require('passport-twitter').Strategy;
|
||||||
var GithubStrategy = require('passport-github').Strategy;
|
var GithubStrategy = require('passport-github').Strategy;
|
||||||
var GitlabStrategy = require('passport-gitlab2').Strategy;
|
var GitlabStrategy = require('passport-gitlab2').Strategy;
|
||||||
var DropboxStrategy = require('passport-dropbox-oauth2').Strategy;
|
var DropboxStrategy = require('passport-dropbox-oauth2').Strategy;
|
||||||
|
var GoogleStrategy = require('passport-google-oauth20').Strategy;
|
||||||
|
|
||||||
//core
|
//core
|
||||||
var config = require('./config.js');
|
var config = require('./config.js');
|
||||||
|
@ -100,4 +101,12 @@ if (config.dropbox) {
|
||||||
clientSecret: config.dropbox.clientSecret,
|
clientSecret: config.dropbox.clientSecret,
|
||||||
callbackURL: config.serverurl + '/auth/dropbox/callback'
|
callbackURL: config.serverurl + '/auth/dropbox/callback'
|
||||||
}, callback));
|
}, callback));
|
||||||
|
}
|
||||||
|
//google
|
||||||
|
if (config.google) {
|
||||||
|
passport.use(new GoogleStrategy({
|
||||||
|
clientID: config.google.clientID,
|
||||||
|
clientSecret: config.google.clientSecret,
|
||||||
|
callbackURL: config.serverurl + '/auth/google/callback'
|
||||||
|
}, callback));
|
||||||
}
|
}
|
|
@ -61,6 +61,7 @@ var twitter = config.twitter || false;
|
||||||
var github = config.github || false;
|
var github = config.github || false;
|
||||||
var gitlab = config.gitlab || false;
|
var gitlab = config.gitlab || false;
|
||||||
var dropbox = config.dropbox || false;
|
var dropbox = config.dropbox || false;
|
||||||
|
var google = config.google || false;
|
||||||
var imgur = config.imgur || false;
|
var imgur = config.imgur || false;
|
||||||
|
|
||||||
function getserverurl() {
|
function getserverurl() {
|
||||||
|
@ -113,5 +114,6 @@ module.exports = {
|
||||||
github: github,
|
github: github,
|
||||||
gitlab: gitlab,
|
gitlab: gitlab,
|
||||||
dropbox: dropbox,
|
dropbox: dropbox,
|
||||||
|
google: google,
|
||||||
imgur: imgur
|
imgur: imgur
|
||||||
};
|
};
|
||||||
|
|
|
@ -76,6 +76,9 @@ module.exports = function (sequelize, DataTypes) {
|
||||||
//no image api provided, use gravatar
|
//no image api provided, use gravatar
|
||||||
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value);
|
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value);
|
||||||
break;
|
break;
|
||||||
|
case "google":
|
||||||
|
photo = profile.photos[0].value.replace(/(\?sz=)\d*$/i, '$196');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return photo;
|
return photo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,8 @@ function showIndex(req, res, next) {
|
||||||
twitter: config.twitter,
|
twitter: config.twitter,
|
||||||
github: config.github,
|
github: config.github,
|
||||||
gitlab: config.gitlab,
|
gitlab: config.gitlab,
|
||||||
dropbox: config.dropbox
|
dropbox: config.dropbox,
|
||||||
|
google: config.google
|
||||||
});
|
});
|
||||||
res.write(content);
|
res.write(content);
|
||||||
res.end();
|
res.end();
|
||||||
|
@ -127,7 +128,8 @@ function responseHackMD(res, note) {
|
||||||
twitter: config.twitter,
|
twitter: config.twitter,
|
||||||
github: config.github,
|
github: config.github,
|
||||||
gitlab: config.gitlab,
|
gitlab: config.gitlab,
|
||||||
dropbox: config.dropbox
|
dropbox: config.dropbox,
|
||||||
|
google: config.google
|
||||||
});
|
});
|
||||||
var buf = html;
|
var buf = html;
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
"passport-facebook": "^2.1.0",
|
"passport-facebook": "^2.1.0",
|
||||||
"passport-github": "^1.1.0",
|
"passport-github": "^1.1.0",
|
||||||
"passport-gitlab2": "^2.2.0",
|
"passport-gitlab2": "^2.2.0",
|
||||||
|
"passport-google-oauth20": "^1.0.0",
|
||||||
"passport-twitter": "^1.0.4",
|
"passport-twitter": "^1.0.4",
|
||||||
"passport.socketio": "^3.6.1",
|
"passport.socketio": "^3.6.1",
|
||||||
"pg": "^4.5.3",
|
"pg": "^4.5.3",
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
<p class="lead">
|
<p class="lead">
|
||||||
Realtime collaborative markdown notes on all platforms.
|
Realtime collaborative markdown notes on all platforms.
|
||||||
</p>
|
</p>
|
||||||
<% if(facebook || twitter || github || gitlab || dropbox) { %>
|
<% if(facebook || twitter || github || gitlab || dropbox || google) { %>
|
||||||
<a type="button" class="btn btn-lg btn-success ui-signin" data-toggle="modal" data-target=".signin-modal" style="display:none;">Sign In</a>
|
<a type="button" class="btn btn-lg btn-success ui-signin" data-toggle="modal" data-target=".signin-modal" style="display:none;">Sign In</a>
|
||||||
<div class="ui-or" style="display:none;">Or</div>
|
<div class="ui-or" style="display:none;">Or</div>
|
||||||
<% }%>
|
<% }%>
|
||||||
|
@ -72,7 +72,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="history" class="section" style="display:none;">
|
<div id="history" class="section" style="display:none;">
|
||||||
<% if(facebook || twitter || github || gitlab || dropbox) { %>
|
<% if(facebook || twitter || github || gitlab || dropbox || google) { %>
|
||||||
<div class="ui-signin">
|
<div class="ui-signin">
|
||||||
<h4>
|
<h4>
|
||||||
<a type="button" class="btn btn-success" data-toggle="modal" data-target=".signin-modal">Sign In</a> to get own history!
|
<a type="button" class="btn btn-success" data-toggle="modal" data-target=".signin-modal">Sign In</a> to get own history!
|
||||||
|
|
|
@ -23,14 +23,19 @@
|
||||||
<i class="fa fa-github"></i> Sign in via GitHub
|
<i class="fa fa-github"></i> Sign in via GitHub
|
||||||
</a>
|
</a>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
<% if(gitlab) { %>
|
||||||
|
<a href="<%- url %>/auth/gitlab" class="btn btn-lg btn-block btn-social btn-soundcloud">
|
||||||
|
<i class="fa fa-gitlab"></i> Sign in via GitLab
|
||||||
|
</a>
|
||||||
|
<% } %>
|
||||||
<% if(dropbox) { %>
|
<% if(dropbox) { %>
|
||||||
<a href="<%- url %>/auth/dropbox" class="btn btn-lg btn-block btn-social btn-dropbox">
|
<a href="<%- url %>/auth/dropbox" class="btn btn-lg btn-block btn-social btn-dropbox">
|
||||||
<i class="fa fa-dropbox"></i> Sign in via Dropbox
|
<i class="fa fa-dropbox"></i> Sign in via Dropbox
|
||||||
</a>
|
</a>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% if(gitlab) { %>
|
<% if(google) { %>
|
||||||
<a href="<%- url %>/auth/gitlab" class="btn btn-lg btn-block btn-social btn-soundcloud">
|
<a href="<%- url %>/auth/google" class="btn btn-lg btn-block btn-social btn-google">
|
||||||
<i class="fa fa-gitlab"></i> Sign in via GitLab
|
<i class="fa fa-google"></i> Sign in via Google
|
||||||
</a>
|
</a>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue