refactor: webpack fixes, missing auth icons, auth resolvers
This commit is contained in:
@@ -33,10 +33,12 @@ module.exports = {
|
||||
// Load authentication strategies
|
||||
|
||||
const modules = _.values(autoload(path.join(WIKI.SERVERPATH, 'modules/authentication')))
|
||||
console.info(WIKI.config.auth)
|
||||
_.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) {
|
||||
console.info(strategy.title)
|
||||
try {
|
||||
strategy.init(passport, strategyConfig)
|
||||
} catch (err) {
|
||||
|
@@ -29,6 +29,30 @@ module.exports = {
|
||||
return prv
|
||||
}
|
||||
},
|
||||
AuthenticationMutation: {
|
||||
async login(obj, args, context) {
|
||||
try {
|
||||
let authResult = await WIKI.db.User.login(args, context)
|
||||
return {
|
||||
...authResult,
|
||||
operation: graphHelper.generateSuccess('Login success')
|
||||
}
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
},
|
||||
async loginTFA(obj, args, context) {
|
||||
try {
|
||||
let authResult = await WIKI.db.User.loginTFA(args, context)
|
||||
return {
|
||||
...authResult,
|
||||
operation: graphHelper.generateSuccess('TFA success')
|
||||
}
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
}
|
||||
},
|
||||
AuthenticationProvider: {
|
||||
icon (ap, args) {
|
||||
return fs.readFile(path.join(WIKI.ROOTPATH, `assets/svg/auth-icon-${ap.key}.svg`), 'utf8').catch(err => {
|
||||
|
@@ -19,22 +19,6 @@ module.exports = {
|
||||
limit: 1
|
||||
})
|
||||
},
|
||||
login(obj, args, context) {
|
||||
return WIKI.db.User.login(args, context).catch(err => {
|
||||
return {
|
||||
succeeded: false,
|
||||
message: err.message
|
||||
}
|
||||
})
|
||||
},
|
||||
loginTFA(obj, args, context) {
|
||||
return WIKI.db.User.loginTFA(args, context).catch(err => {
|
||||
return {
|
||||
succeeded: false,
|
||||
message: err.message
|
||||
}
|
||||
})
|
||||
},
|
||||
modifyUser(obj, args) {
|
||||
return WIKI.db.User.update({
|
||||
email: args.email,
|
||||
|
@@ -1,3 +1,7 @@
|
||||
# ===============================================
|
||||
# AUTHENTICATION
|
||||
# ===============================================
|
||||
|
||||
extend type Query {
|
||||
authentication: AuthenticationQuery
|
||||
}
|
||||
@@ -6,6 +10,10 @@ extend type Mutation {
|
||||
authentication: AuthenticationMutation
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# QUERIES
|
||||
# -----------------------------------------------
|
||||
|
||||
type AuthenticationQuery {
|
||||
providers(
|
||||
filter: String
|
||||
@@ -13,7 +21,22 @@ type AuthenticationQuery {
|
||||
): [AuthenticationProvider]
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# MUTATIONS
|
||||
# -----------------------------------------------
|
||||
|
||||
type AuthenticationMutation {
|
||||
login(
|
||||
username: String!
|
||||
password: String!
|
||||
provider: String!
|
||||
): AuthenticationLoginResponse
|
||||
|
||||
loginTFA(
|
||||
loginToken: String!
|
||||
securityCode: String!
|
||||
): DefaultResponse
|
||||
|
||||
updateProvider(
|
||||
provider: String!
|
||||
isEnabled: Boolean!
|
||||
@@ -21,6 +44,10 @@ type AuthenticationMutation {
|
||||
): DefaultResponse
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# TYPES
|
||||
# -----------------------------------------------
|
||||
|
||||
type AuthenticationProvider {
|
||||
isEnabled: Boolean!
|
||||
key: String!
|
||||
@@ -30,3 +57,9 @@ type AuthenticationProvider {
|
||||
icon: String
|
||||
config: [KeyValuePair]
|
||||
}
|
||||
|
||||
type AuthenticationLoginResponse {
|
||||
operation: ResponseStatus
|
||||
tfaRequired: Boolean
|
||||
tfaLoginToken: String
|
||||
}
|
||||
|
@@ -162,13 +162,6 @@ type OperationResult {
|
||||
data: String
|
||||
}
|
||||
|
||||
type LoginResult {
|
||||
succeeded: Boolean!
|
||||
message: String
|
||||
tfaRequired: Boolean
|
||||
tfaLoginToken: String
|
||||
}
|
||||
|
||||
# Query (Read)
|
||||
type Query {
|
||||
comments(id: Int): [Comment]
|
||||
@@ -265,17 +258,6 @@ type Mutation {
|
||||
id: Int!
|
||||
): OperationResult
|
||||
|
||||
login(
|
||||
username: String!
|
||||
password: String!
|
||||
provider: String!
|
||||
): LoginResult
|
||||
|
||||
loginTFA(
|
||||
loginToken: String!
|
||||
securityCode: String!
|
||||
): OperationResult
|
||||
|
||||
modifyComment(
|
||||
id: Int!
|
||||
content: String!
|
||||
|
@@ -2,6 +2,23 @@ const _ = require('lodash')
|
||||
const Filter = require('scim-query-filter-parser')
|
||||
|
||||
module.exports = {
|
||||
generateSuccess (msg) {
|
||||
return {
|
||||
succeeded: true,
|
||||
code: 0,
|
||||
slug: 'ok',
|
||||
message: _.defaultTo(msg, 'Operation succeeded.')
|
||||
}
|
||||
},
|
||||
generateError (err, complete = true) {
|
||||
const error = {
|
||||
succeeded: false,
|
||||
code: err.code || 1,
|
||||
slug: err.name,
|
||||
message: err.message || 'An unexpected error occured.'
|
||||
}
|
||||
return (complete) ? { operation: error } : error
|
||||
},
|
||||
filter (arr, filterString) {
|
||||
const prvFilter = new Filter(_.toString(filterString).replace(/'/g, `"`))
|
||||
return arr.filter(prvFilter.test)
|
||||
|
@@ -103,8 +103,6 @@ module.exports = (sequelize, DataTypes) => {
|
||||
let loginToken = await securityHelper.generateToken(32)
|
||||
await WIKI.redis.set(`tfa:${loginToken}`, user.id, 'EX', 600)
|
||||
return resolve({
|
||||
succeeded: true,
|
||||
message: 'Login Successful. Awaiting 2FA security code.',
|
||||
tfaRequired: true,
|
||||
tfaLoginToken: loginToken
|
||||
})
|
||||
@@ -117,8 +115,6 @@ module.exports = (sequelize, DataTypes) => {
|
||||
return context.req.logIn(user, err => {
|
||||
if (err) { return reject(err) }
|
||||
resolve({
|
||||
succeeded: true,
|
||||
message: 'Login Successful',
|
||||
tfaRequired: false
|
||||
})
|
||||
})
|
||||
|
6
server/views/main/setup.pug
Normal file
6
server/views/main/setup.pug
Normal file
@@ -0,0 +1,6 @@
|
||||
extends ../master.pug
|
||||
|
||||
block body
|
||||
body
|
||||
#app.setup.is-fullscreen
|
||||
setup(telemetry-id=telemetryClientID, wiki-version=packageObj.version, :langs!=JSON.stringify(data.langs).replace(/"/g, "'"))
|
Reference in New Issue
Block a user