feat: vue-apollo + auth providers resolver (wip)

This commit is contained in:
NGPixel
2018-03-05 20:53:24 -05:00
parent 91b575529c
commit f5fb21aaba
14 changed files with 158 additions and 558 deletions

View File

@@ -31,7 +31,7 @@ defaults:
public: false
strategies:
local:
enabled: true
isEnabled: true
allowSelfRegister: false
git:
enabled: false

View File

@@ -4,6 +4,7 @@ const _ = require('lodash')
const passport = require('passport')
const fs = require('fs-extra')
const path = require('path')
const autoload = require('auto-load')
module.exports = {
strategies: {},
@@ -31,26 +32,29 @@ module.exports = {
// Load authentication strategies
_.forOwn(_.omitBy(WIKI.config.auth.strategies, s => s.enabled === false), (strategyConfig, strategyKey) => {
strategyConfig.callbackURL = `${WIKI.config.site.host}${WIKI.config.site.path}login/${strategyKey}/callback`
let strategy = require(`../modules/authentication/${strategyKey}`)
try {
strategy.init(passport, strategyConfig)
} catch (err) {
WIKI.logger.error(`Authentication Provider ${strategyKey}: [ FAILED ]`)
WIKI.logger.error(err)
const modules = _.values(autoload(path.join(WIKI.SERVERPATH, 'modules/authentication')))
_.forEach(modules, (strategy) => {
const strategyConfig = _.get(WIKI.config.auth.strategies, strategy.key, {})
strategyConfig.callbackURL = `${WIKI.config.site.host}${WIKI.config.site.path}login/${strategy.key}/callback`
if (strategyConfig.isEnabled) {
try {
strategy.init(passport, strategyConfig)
} catch (err) {
WIKI.logger.error(`Authentication Provider ${strategy.title}: [ FAILED ]`)
WIKI.logger.error(err)
}
}
fs.readFile(path.join(WIKI.ROOTPATH, `assets/svg/auth-icon-${strategyKey}.svg`), 'utf8').then(iconData => {
fs.readFile(path.join(WIKI.ROOTPATH, `assets/svg/auth-icon-${strategy.key}.svg`), 'utf8').then(iconData => {
strategy.icon = iconData
}).catch(err => {
if (err.code === 'ENOENT') {
strategy.icon = '[missing icon]'
} else {
WIKI.logger.error(err)
WIKI.logger.warn(err)
}
})
this.strategies[strategy.key] = strategy
WIKI.logger.info(`Authentication Provider ${strategyKey}: [ OK ]`)
WIKI.logger.info(`Authentication Provider ${strategy.title}: [ OK ]`)
})
// Create Guest account for first-time

View File

@@ -13,28 +13,19 @@ module.exports = {
},
AuthenticationQuery: {
providers(obj, args, context, info) {
switch (args.mode) {
case 'active':
let strategies = _.chain(WIKI.auth.strategies).map(str => {
return {
key: str.key,
title: str.title,
useForm: str.useForm
}
}).sortBy(['title']).value()
let localStrategy = _.remove(strategies, str => str.key === 'local')
return _.concat(localStrategy, strategies)
case 'all':
break
default:
return null
}
return _.chain(WIKI.auth.strategies).map(str => {
return {
isEnabled: true,
key: str.key,
title: str.title,
useForm: str.useForm
}
}).sortBy(['title']).value()
}
},
AuthenticationProvider: {
icon (ap, args) {
return fs.readFileAsync(path.join(WIKI.ROOTPATH, `assets/svg/auth-icon-${ap.key}.svg`), 'utf8').catch(err => {
return fs.readFile(path.join(WIKI.ROOTPATH, `assets/svg/auth-icon-${ap.key}.svg`), 'utf8').catch(err => {
if (err.code === 'ENOENT') {
return null
}

View File

@@ -10,7 +10,13 @@ type AuthenticationQuery {
providers: [AuthenticationProvider]
}
type AuthenticationMutation
type AuthenticationMutation {
updateProvider(
provider: String!
isEnabled: Boolean!
config: [KeyValuePairInput]
): DefaultResponse
}
type AuthenticationProvider {
isEnabled: Boolean!
@@ -19,5 +25,5 @@ type AuthenticationProvider {
title: String!
useForm: Boolean!
icon: String
config: String
config: [KeyValuePair]
}

View File

@@ -29,6 +29,26 @@ interface Base {
# TYPES
type KeyValuePair {
key: String!
value: String!
}
input KeyValuePairInput {
key: String!
value: String!
}
type DefaultResponse {
operation: ResponseStatus
}
type ResponseStatus {
succeeded: Boolean!
code: Int!
slug: String!
message: String
}
type Comment implements Base {
id: Int!
createdAt: Date

View File

@@ -17,10 +17,6 @@ let WIKI = {
}
global.WIKI = WIKI
// if (WIKI.IS_DEBUG) {
// require('@glimpse/glimpse').init()
// }
WIKI.configSvc.init()
// ----------------------------------------