From a155af20f5d12f5d94ef1d1d69e8eae23b77616f Mon Sep 17 00:00:00 2001 From: NGPixel Date: Sun, 31 Dec 2017 14:40:28 -0500 Subject: [PATCH] feat: added auth0, discord, twitch auth modules --- client/js/components/login.vue | 7 ++-- client/js/components/navigator.vue | 24 +++++++++----- client/scss/components/login.scss | 4 +-- client/svg/icons.svg | 21 ++++++++++-- package.json | 3 ++ server/extensions/authentication/auth0.js | 30 ++++++++++++++++++ server/extensions/authentication/azure.js | 2 +- server/extensions/authentication/discord.js | 30 ++++++++++++++++++ server/extensions/authentication/facebook.js | 2 +- server/extensions/authentication/github.js | 2 +- server/extensions/authentication/google.js | 2 +- server/extensions/authentication/microsoft.js | 2 +- server/extensions/authentication/slack.js | 2 +- server/extensions/authentication/twitch.js | 30 ++++++++++++++++++ yarn.lock | Bin 304357 -> 305147 bytes 15 files changed, 140 insertions(+), 21 deletions(-) create mode 100644 server/extensions/authentication/auth0.js create mode 100644 server/extensions/authentication/discord.js create mode 100644 server/extensions/authentication/twitch.js diff --git a/client/js/components/login.vue b/client/js/components/login.vue index d50fcbd7..2a9164ee 100644 --- a/client/js/components/login.vue +++ b/client/js/components/login.vue @@ -9,9 +9,9 @@ .login-frame h1 {{ siteTitle }} h2 {{ $t('auth:loginrequired') }} - input(type='text', name='email', :placeholder='$t("auth:fields.emailuser")') - input(type='password', name='password', :placeholder='$t("auth:fields.password")') - button.button.is-orange.is-fullwidth(@click='login') + input(type='text', ref='iptEmail', :placeholder='$t("auth:fields.emailuser")') + input(type='password', ref='iptPassword', :placeholder='$t("auth:fields.password")') + button.button.is-blue.is-fullwidth(@click='login') span {{ $t('auth:actions.login') }} .login-copyright span {{ $t('footer.poweredby') }} @@ -69,6 +69,7 @@ export default { mounted() { this.$store.commit('navigator/subtitleStatic', 'Login') this.refreshStrategies() + this.$refs.iptEmail.focus() } } diff --git a/client/js/components/navigator.vue b/client/js/components/navigator.vue index a768e73c..3c255560 100644 --- a/client/js/components/navigator.vue +++ b/client/js/components/navigator.vue @@ -22,26 +22,34 @@ transition(name='navigator-sd') .navigator-sd(v-show='sdShown') .navigator-sd-actions - a.is-active(href='') + a.is-active(href='', title='Search') svg.icons.is-24(role='img') title Search use(xlink:href='#gg-search') a(href='') - svg.icons.is-24(role='img') + svg.icons.is-24(role='img', title='New Document') title New Document use(xlink:href='#nc-plus-circle') a(href='') - svg.icons.is-24(role='img') - title Navigation + svg.icons.is-24(role='img', title='Edit Document') + title Edit Document use(xlink:href='#nc-pen-red') a(href='') - svg.icons.is-24(role='img') - title Navigation + svg.icons.is-24(role='img', title='History') + title History use(xlink:href='#nc-restore') a(href='') - svg.icons.is-24(role='img') - title New Document + svg.icons.is-24(role='img', title='View Source') + title View Source use(xlink:href='#nc-code-editor') + a(href='') + svg.icons.is-24(role='img', title='Move Document') + title Move Document + use(xlink:href='#nc-move') + a(href='') + svg.icons.is-24(role='img', title='Delete Document') + title Delete Document + use(xlink:href='#nc-trash') .navigator-sd-search input(type='text', placeholder='Search') .navigator-sd-results diff --git a/client/scss/components/login.scss b/client/scss/components/login.scss index e9dd5166..104c9623 100644 --- a/client/scss/components/login.scss +++ b/client/scss/components/login.scss @@ -229,7 +229,7 @@ .login { input[type=text], input[type=password] { width: 100%; - border: 1px solid rgba(mc('light-blue','500'), .5); + border: 1px solid rgba(mc('blue-grey','500'), .5); border-radius: 3px; background-color: rgba(255,255,255,.9); box-shadow: inset 0 0 0 3px rgba(255,255,255, .25); @@ -253,7 +253,7 @@ .login { } .button { - background-image: linear-gradient(to top, mc('deep-orange', '400') 0%, mc('deep-orange', '400') 50%, mc('orange', '500') 100%); + background-image: linear-gradient(to bottom, mc('blue', '400') 0%, mc('blue', '600') 50%, mc('blue', '700') 100%); background-repeat: no-repeat; background-size: 100% 200%; diff --git a/client/svg/icons.svg b/client/svg/icons.svg index 653360b4..6c85ebdc 100644 --- a/client/svg/icons.svg +++ b/client/svg/icons.svg @@ -1,4 +1,5 @@ - + @@ -389,7 +390,7 @@ - + @@ -410,4 +411,20 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/package.json b/package.json index 471aa9f1..b763c21d 100644 --- a/package.json +++ b/package.json @@ -100,13 +100,16 @@ "node-graceful": "0.2.3", "ora": "1.3.0", "passport": "0.4.0", + "passport-auth0": "0.6.1", "passport-azure-ad-oauth2": "0.0.4", + "passport-discord": "0.1.3", "passport-facebook": "2.1.1", "passport-github2": "0.1.11", "passport-google-oauth20": "1.0.0", "passport-ldapauth": "2.0.0", "passport-local": "1.0.0", "passport-slack": "0.0.7", + "passport-twitch": "1.0.3", "passport-windowslive": "1.0.2", "pg": "6.4.2", "pg-hstore": "2.3.2", diff --git a/server/extensions/authentication/auth0.js b/server/extensions/authentication/auth0.js new file mode 100644 index 00000000..63146980 --- /dev/null +++ b/server/extensions/authentication/auth0.js @@ -0,0 +1,30 @@ +/* global wiki */ + +// ------------------------------------ +// Auth0 Account +// ------------------------------------ + +const Auth0Strategy = require('passport-auth0').Strategy + +module.exports = { + key: 'auth0', + title: 'Auth0', + useForm: false, + props: ['domain', 'clientId', 'clientSecret'], + init (passport, conf) { + passport.use('auth0', + new Auth0Strategy({ + domain: conf.domain, + clientID: conf.clientId, + clientSecret: conf.clientSecret, + callbackURL: conf.callbackURL + }, function (accessToken, refreshToken, profile, cb) { + wiki.db.User.processProfile(profile).then((user) => { + return cb(null, user) || true + }).catch((err) => { + return cb(err, null) || true + }) + } + )) + } +} diff --git a/server/extensions/authentication/azure.js b/server/extensions/authentication/azure.js index 29ae7214..5d75bd4f 100644 --- a/server/extensions/authentication/azure.js +++ b/server/extensions/authentication/azure.js @@ -10,7 +10,7 @@ module.exports = { key: 'azure', title: 'Azure Active Directory', useForm: false, - props: ['clientId', 'clientSecret', 'callbackURL', 'resource', 'tenant'], + props: ['clientId', 'clientSecret', 'resource', 'tenant'], init (passport, conf) { const jwt = require('jsonwebtoken') passport.use('azure_ad_oauth2', diff --git a/server/extensions/authentication/discord.js b/server/extensions/authentication/discord.js new file mode 100644 index 00000000..eb2676c2 --- /dev/null +++ b/server/extensions/authentication/discord.js @@ -0,0 +1,30 @@ +/* global wiki */ + +// ------------------------------------ +// Discord Account +// ------------------------------------ + +const DiscordStrategy = require('passport-discord').Strategy + +module.exports = { + key: 'discord', + title: 'Discord', + useForm: false, + props: ['clientId', 'clientSecret'], + init (passport, conf) { + passport.use('discord', + new DiscordStrategy({ + clientID: conf.clientId, + clientSecret: conf.clientSecret, + callbackURL: conf.callbackURL, + scope: 'identify email' + }, function (accessToken, refreshToken, profile, cb) { + wiki.db.User.processProfile(profile).then((user) => { + return cb(null, user) || true + }).catch((err) => { + return cb(err, null) || true + }) + } + )) + } +} diff --git a/server/extensions/authentication/facebook.js b/server/extensions/authentication/facebook.js index bade7ac0..f0e33da5 100644 --- a/server/extensions/authentication/facebook.js +++ b/server/extensions/authentication/facebook.js @@ -10,7 +10,7 @@ module.exports = { key: 'facebook', title: 'Facebook', useForm: false, - props: ['clientId', 'clientSecret', 'callbackURL'], + props: ['clientId', 'clientSecret'], init (passport, conf) { passport.use('facebook', new FacebookStrategy({ diff --git a/server/extensions/authentication/github.js b/server/extensions/authentication/github.js index f2d5727c..941ced15 100644 --- a/server/extensions/authentication/github.js +++ b/server/extensions/authentication/github.js @@ -10,7 +10,7 @@ module.exports = { key: 'github', title: 'GitHub', useForm: false, - props: ['clientId', 'clientSecret', 'callbackURL'], + props: ['clientId', 'clientSecret'], init (passport, conf) { passport.use('github', new GitHubStrategy({ diff --git a/server/extensions/authentication/google.js b/server/extensions/authentication/google.js index 73995f54..e2fb4824 100644 --- a/server/extensions/authentication/google.js +++ b/server/extensions/authentication/google.js @@ -10,7 +10,7 @@ module.exports = { key: 'google', title: 'Google ID', useForm: false, - props: ['clientId', 'clientSecret', 'callbackURL'], + props: ['clientId', 'clientSecret'], init (passport, conf) { passport.use('google', new GoogleStrategy({ diff --git a/server/extensions/authentication/microsoft.js b/server/extensions/authentication/microsoft.js index 9bf9c7d9..1f61dbbb 100644 --- a/server/extensions/authentication/microsoft.js +++ b/server/extensions/authentication/microsoft.js @@ -10,7 +10,7 @@ module.exports = { key: 'microsoft', title: 'Microsoft Account', useForm: false, - props: ['clientId', 'clientSecret', 'callbackURL'], + props: ['clientId', 'clientSecret'], init (passport, conf) { passport.use('microsoft', new WindowsLiveStrategy({ diff --git a/server/extensions/authentication/slack.js b/server/extensions/authentication/slack.js index 04cedcb1..04d49c1d 100644 --- a/server/extensions/authentication/slack.js +++ b/server/extensions/authentication/slack.js @@ -10,7 +10,7 @@ module.exports = { key: 'slack', title: 'Slack', useForm: false, - props: ['clientId', 'clientSecret', 'callbackURL'], + props: ['clientId', 'clientSecret'], init (passport, conf) { passport.use('slack', new SlackStrategy({ diff --git a/server/extensions/authentication/twitch.js b/server/extensions/authentication/twitch.js new file mode 100644 index 00000000..0dae0c1d --- /dev/null +++ b/server/extensions/authentication/twitch.js @@ -0,0 +1,30 @@ +/* global wiki */ + +// ------------------------------------ +// Twitch Account +// ------------------------------------ + +const TwitchStrategy = require('passport-twitch').Strategy + +module.exports = { + key: 'twitch', + title: 'Twitch', + useForm: false, + props: ['clientId', 'clientSecret'], + init (passport, conf) { + passport.use('twitch', + new TwitchStrategy({ + clientID: conf.clientId, + clientSecret: conf.clientSecret, + callbackURL: conf.callbackURL, + scope: 'user_read' + }, function (accessToken, refreshToken, profile, cb) { + wiki.db.User.processProfile(profile).then((user) => { + return cb(null, user) || true + }).catch((err) => { + return cb(err, null) || true + }) + } + )) + } +} diff --git a/yarn.lock b/yarn.lock index 3b7360245cbe064bedcdd8066824da143b6d1b42..9cc2de1ba3190cf8b0867c6e87b1486dbfe8f282 100644 GIT binary patch delta 472 zcmZXQyGjE=6hO(2@qyqYg^G;<(SwyG)4K}x!-s-gj_3Y>&(y#_Qt2yu(U0I9&G*$XhIPH)9g@0V8 zP9k%yuY?wSM3Q~*Jo9%+K1@fpf_Z2A0BnFU@3`!-Qd;)TBVp1`NQR3-q9P3rf^19) zMMYO2M>lOwh%j*x`dyCB2qM(sq$n)b+H3v>`4`LEJcxHL3*fckKekiof~%KrJI9#R delta 67 zcmex;Ug+sbp@tU57N#xC9)8nz`ZM!Q5A