feat: setup TFA

This commit is contained in:
NGPixel
2023-10-01 07:33:10 +00:00
parent 7c2b5dd4dd
commit fe8066c8f4
13 changed files with 383 additions and 273 deletions
+11 -7
View File
@@ -46,7 +46,7 @@ export default {
return {
...a,
config: _.transform(str.props, (r, v, k) => {
r[k] = v.sensitive ? a.config[k] : '********'
r[k] = v.sensitive ? '********' : a.config[k]
}, {})
}
})
@@ -102,7 +102,7 @@ export default {
if (args.strategy === 'ldap' && WIKI.config.flags.ldapdebug) {
WIKI.logger.warn('LDAP LOGIN ERROR (c1): ', err)
}
console.error(err)
WIKI.logger.debug(err)
return generateError(err)
}
@@ -115,9 +115,10 @@ export default {
const authResult = await WIKI.db.users.loginTFA(args, context)
return {
...authResult,
responseResult: generateSuccess('TFA success')
operation: generateSuccess('TFA success')
}
} catch (err) {
WIKI.logger.debug(err)
return generateError(err)
}
},
@@ -129,9 +130,10 @@ export default {
const authResult = await WIKI.db.users.loginChangePassword(args, context)
return {
...authResult,
responseResult: generateSuccess('Password changed successfully')
operation: generateSuccess('Password changed successfully')
}
} catch (err) {
WIKI.logger.debug(err)
return generateError(err)
}
},
@@ -142,7 +144,7 @@ export default {
try {
await WIKI.db.users.loginForgotPassword(args, context)
return {
responseResult: generateSuccess('Password reset request processed.')
operation: generateSuccess('Password reset request processed.')
}
} catch (err) {
return generateError(err)
@@ -153,9 +155,11 @@ export default {
*/
async register (obj, args, context) {
try {
await WIKI.db.users.register({ ...args, verify: true }, context)
const usr = await WIKI.db.users.createNewUser({ ...args, userInitiated: true })
const authResult = await WIKI.db.users.afterLoginChecks(usr, WIKI.data.systemIds.localAuthId, context)
return {
responseResult: generateSuccess('Registration success')
...authResult,
operation: generateSuccess('Registration success')
}
} catch (err) {
return generateError(err)
+19 -17
View File
@@ -30,14 +30,16 @@ extend type Mutation {
username: String!
password: String!
strategyId: UUID!
siteId: UUID
): AuthenticationLoginResponse @rateLimit(limit: 5, duration: 60)
siteId: UUID!
): AuthenticationAuthResponse @rateLimit(limit: 5, duration: 60)
loginTFA(
continuationToken: String!
securityCode: String!
strategyId: UUID!
siteId: UUID!
setup: Boolean
): AuthenticationLoginResponse @rateLimit(limit: 5, duration: 60)
): AuthenticationAuthResponse @rateLimit(limit: 5, duration: 60)
changePassword(
userId: UUID
@@ -46,7 +48,7 @@ extend type Mutation {
newPassword: String!
strategyId: UUID!
siteId: UUID
): AuthenticationLoginResponse @rateLimit(limit: 5, duration: 60)
): AuthenticationAuthResponse @rateLimit(limit: 5, duration: 60)
forgotPassword(
email: String!
@@ -56,7 +58,7 @@ extend type Mutation {
email: String!
password: String!
name: String!
): AuthenticationRegisterResponse
): AuthenticationAuthResponse @rateLimit(limit: 5, duration: 60)
refreshToken(
token: String!
@@ -105,7 +107,7 @@ type AuthenticationActiveStrategy {
displayName: String
isEnabled: Boolean
config: JSON
selfRegistration: Boolean
registration: Boolean
allowedEmailRegex: String
autoEnrollGroups: [UUID]
}
@@ -116,22 +118,15 @@ type AuthenticationSiteStrategy {
isVisible: Boolean
}
type AuthenticationLoginResponse {
type AuthenticationAuthResponse {
operation: Operation
jwt: String
mustChangePwd: Boolean
mustProvideTFA: Boolean
mustSetupTFA: Boolean
nextAction: AuthenticationNextAction
continuationToken: String
redirect: String
tfaQRImage: String
}
type AuthenticationRegisterResponse {
operation: Operation
jwt: String
}
type AuthenticationTokenResponse {
operation: Operation
jwt: String
@@ -140,11 +135,11 @@ type AuthenticationTokenResponse {
input AuthenticationStrategyInput {
key: String!
strategyKey: String!
config: [KeyValuePairInput]
config: JSON!
displayName: String!
order: Int!
isEnabled: Boolean!
selfRegistration: Boolean!
registration: Boolean!
allowedEmailRegex: String!
autoEnrollGroups: [UUID]!
}
@@ -163,3 +158,10 @@ type AuthenticationCreateApiKeyResponse {
operation: Operation
key: String
}
enum AuthenticationNextAction {
changePassword
setupTfa
provideTfa
redirect
}