Added GitHub and Slack authentication integrations

This commit is contained in:
NGPixel 2017-02-24 16:50:04 -05:00
parent ee16b82f17
commit 9976842e45
13 changed files with 60 additions and 13 deletions

View File

@ -29,6 +29,10 @@ defaults:
enabled: false
facebook:
enabled: false
github:
enabled: false
slack:
enabled: false
db: mongodb://localhost/wiki
sessionSecret: null
admin: null

File diff suppressed because one or more lines are too long

View File

@ -68,6 +68,16 @@ auth:
enabled: false
clientId: FACEBOOK_APP_ID
clientSecret: FACEBOOK_APP_SECRET
github:
enabled: false
clientId: GITHUB_CLIENT_ID
clientSecret: GITHUB_CLIENT_SECRET
slack:
enabled: false
clientId: SLACK_CLIENT_ID
clientSecret: SLACK_CLIENT_SECRET
ldap:
enabled: false
# ---------------------------------------------------------------------
# Secret key to use when encrypting sessions

View File

@ -123,7 +123,7 @@ router.post('/users/create', (req, res) => {
if (!validator.isEmail(nUsr.email)) {
return res.status(400).json({ msg: 'Invalid email address' })
} else if (!validator.isIn(nUsr.provider, ['local', 'google', 'windowslive', 'facebook'])) {
} else if (!validator.isIn(nUsr.provider, ['local', 'google', 'windowslive', 'facebook', 'github', 'slack'])) {
return res.status(400).json({ msg: 'Invalid provider' })
} else if (nUsr.provider === 'local' && !validator.isLength(nUsr.password, { min: 6 })) {
return res.status(400).json({ msg: 'Password too short or missing' })

View File

@ -64,10 +64,14 @@ router.post('/login', bruteforce.prevent, function (req, res, next) {
router.get('/login/ms', passport.authenticate('windowslive', { scope: ['wl.signin', 'wl.basic', 'wl.emails'] }))
router.get('/login/google', passport.authenticate('google', { scope: ['profile', 'email'] }))
router.get('/login/facebook', passport.authenticate('facebook', { scope: ['public_profile', 'email'] }))
router.get('/login/github', passport.authenticate('github', { scope: ['user:email'] }))
router.get('/login/slack', passport.authenticate('slack', { scope: ['identity.basic', 'identity.email'] }))
router.get('/login/ms/callback', passport.authenticate('windowslive', { failureRedirect: '/login', successRedirect: '/' }))
router.get('/login/google/callback', passport.authenticate('google', { failureRedirect: '/login', successRedirect: '/' }))
router.get('/login/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login', successRedirect: '/' }))
router.get('/login/github/callback', passport.authenticate('github', { failureRedirect: '/login', successRedirect: '/' }))
router.get('/login/slack/callback', passport.authenticate('slack', { failureRedirect: '/login', successRedirect: '/' }))
/**
* Logout

View File

@ -3,6 +3,8 @@
"local": "Local",
"windowslive": "Microsoft Account",
"google": "Google ID",
"facebook": "Facebook"
"facebook": "Facebook",
"github": "GitHub",
"slack": "Slack"
}
}
}

View File

@ -50,10 +50,14 @@ userSchema.statics.processProfile = (profile) => {
primaryEmail = (e) ? e.value : _.first(profile.emails).value
} else if (_.isString(profile.email) && profile.email.length > 5) {
primaryEmail = profile.email
} else if (profile.user && profile.user.email && profile.user.email.length > 5) {
primaryEmail = profile.user.email
} else {
return Promise.reject(new Error('Invalid User Email'))
}
profile.provider = _.lowerCase(profile.provider)
return db.User.findOneAndUpdate({
email: primaryEmail,
provider: profile.provider

View File

@ -83,10 +83,7 @@
"multer": "^1.2.1",
"ora": "^1.1.0",
"passport": "^0.3.2",
"passport-facebook": "^2.1.1",
"passport-google-oauth20": "^1.0.0",
"passport-local": "^1.0.0",
"passport-windowslive": "^1.0.2",
"passport.socketio": "^3.7.0",
"pm2": "^2.4.0",
"pug": "^2.0.0-beta11",

View File

@ -50,18 +50,26 @@ html
span Log in using...
if appconfig.auth.microsoft && appconfig.auth.microsoft.enabled
button.ms(onclick='window.location.assign("/login/ms")')
i.fa.fa-windows
i.icon-windows2
span Microsoft Account
if appconfig.auth.google && appconfig.auth.google.enabled
button.google(onclick='window.location.assign("/login/google")')
i.fa.fa-google
i.icon-google
span Google ID
if appconfig.auth.facebook && appconfig.auth.facebook.enabled
button.facebook(onclick='window.location.assign("/login/facebook")')
i.fa.fa-facebook
i.icon-facebook
span Facebook
if appconfig.auth.github && appconfig.auth.github.enabled
button.github(onclick='window.location.assign("/login/github")')
i.icon-github
span GitHub
if appconfig.auth.slack && appconfig.auth.slack.enabled
button.slack(onclick='window.location.assign("/login/slack")')
i.icon-slack
span Slack
#copyright
= t('footer.poweredby') + ' '
a.icon(href='https://github.com/Requarks/wiki')
i.icon-github
a(href='https://github.com/Requarks/wiki') Requarks Wiki
a(href='https://wiki.requarks.io/') Wiki.js

View File

@ -21,6 +21,10 @@
option(value='google') Google ID
if appconfig.auth.facebook.enabled
option(value='facebook') Facebook
if appconfig.auth.github.enabled
option(value='github') GitHub
if appconfig.auth.slack.enabled
option(value='slack') Slack
section(v-if='provider=="local"')
label.label Password:
p.control.is-fullwidth

View File

@ -37,7 +37,9 @@ block adminContent
when 'local': i.icon-server
when 'windowslive': i.icon-windows2.is-blue
when 'google': i.icon-google.is-blue
when 'facebook': i.icon-facebook.is-purple
when 'facebook': i.icon-facebook.is-indigo
when 'github': i.icon-github.is-grey
when 'slack': i.icon-slack.is-purple
default: i.icon-warning
= t('auth:providers.' + user.provider)
label.label Member since

View File

@ -34,8 +34,14 @@ block adminContent
i.icon-google.is-blue
| Google ID
when 'facebook'
i.icon-facebook.is-purple
i.icon-facebook.is-indigo
| Facebook
when 'github'
i.icon-github.is-blue-grey
| GitHub
when 'slack'
i.icon-slack.is-purple
| Slack
default: i.icon-warning
td.is-centered= userMoment(usr.createdAt).format('lll')
td.is-centered= userMoment(usr.updatedAt).format('lll')

View File

@ -43,6 +43,12 @@ block adminContent
when 'facebook'
i.icon-facebook.is-purple
| Facebook
when 'github'
i.icon-github.is-blue-grey
| GitHub
when 'slack'
i.icon-slack.is-purple
| Slack
default: i.icon-warning
td.is-centered= userMoment(usr.createdAt).format('lll')
td.is-centered= userMoment(usr.updatedAt).format('lll')