@live-change/password-authentication-service 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/clientPasswordValidator.js +9 -0
- package/index.js +78 -0
- package/package.json +28 -0
- package/passwordValidator.js +9 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default (settings) => (pass) => {
|
|
2
|
+
if(!pass) return
|
|
3
|
+
let digits = /\d/.test(pass)
|
|
4
|
+
let lower = /[a-z]/.test(pass)
|
|
5
|
+
let upper = /[A-Z]/.test(pass)
|
|
6
|
+
let safe = pass.length >= 8 && digits && lower && upper
|
|
7
|
+
if (pass.length >= 15) safe = true
|
|
8
|
+
if (!safe) return "unsafePassword"
|
|
9
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const autoValidation = require('@live-change/framework/lib/processors/autoValidation')
|
|
2
|
+
const nodemailer = require('nodemailer')
|
|
3
|
+
const app = require("@live-change/framework").app()
|
|
4
|
+
|
|
5
|
+
const definition = app.createServiceDefinition({
|
|
6
|
+
name: "passwordAuthentication"
|
|
7
|
+
})
|
|
8
|
+
const config = definition.config
|
|
9
|
+
|
|
10
|
+
const secretProperties = {
|
|
11
|
+
passwordHash: {
|
|
12
|
+
type: String,
|
|
13
|
+
secret: true,
|
|
14
|
+
preFilter: config.passwordHash ||
|
|
15
|
+
(password => password && crypto.createHash('sha256').update(password).digest('hex')),
|
|
16
|
+
validation: config.passwordValidation || ['password']
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
for(const contactType of config.contactTypes) {
|
|
21
|
+
const contactTypeUpperCaseName = contactType[0].toUpperCase() + contactType.slice(1)
|
|
22
|
+
|
|
23
|
+
const contactConfig = (typeof contactType == "string") ? { name: contactType } : contactType
|
|
24
|
+
|
|
25
|
+
const contactTypeName = contactConfig.name
|
|
26
|
+
const contactTypeUName = contactTypeName[0].toUpperCase() + contactTypeName.slice(1)
|
|
27
|
+
|
|
28
|
+
const contactTypeProperties = {
|
|
29
|
+
[contactType]: {
|
|
30
|
+
type: String,
|
|
31
|
+
validation: ['nonEmpty', contactTypeName]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
definition.action({
|
|
36
|
+
name: 'signIn' + contactTypeUpperCaseName,
|
|
37
|
+
waitForEvents: true,
|
|
38
|
+
properties: {
|
|
39
|
+
...contactTypeProperties,
|
|
40
|
+
...secretProperties
|
|
41
|
+
},
|
|
42
|
+
async execute({ [contactTypeName]: contact, passwordHash }, { client, service }, emit) {
|
|
43
|
+
await service.trigger({
|
|
44
|
+
type: 'checkExisting' + contactTypeUName,
|
|
45
|
+
[contactType]: contact,
|
|
46
|
+
})
|
|
47
|
+
if(passwordHash) { // login with password
|
|
48
|
+
throw Error('not implemented yet')
|
|
49
|
+
} else { // login without password - with message
|
|
50
|
+
if(!config.signInWithoutPassword) throw { properties: { passwordHash: 'empty' } }
|
|
51
|
+
const contactData = (await service.trigger({
|
|
52
|
+
type: 'get' + contactTypeUName,
|
|
53
|
+
[contactType]: contact,
|
|
54
|
+
}))[0]
|
|
55
|
+
const messageData = {
|
|
56
|
+
user: contactData.user
|
|
57
|
+
}
|
|
58
|
+
const results = await service.trigger({
|
|
59
|
+
type: 'authenticateWithMessage',
|
|
60
|
+
contactType,
|
|
61
|
+
contact,
|
|
62
|
+
messageData,
|
|
63
|
+
action: 'signInWithMessage',
|
|
64
|
+
targetPage: config.signInTargetPage || { name: 'user:signInFinished' }
|
|
65
|
+
})
|
|
66
|
+
return results[0]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
definition.processor(function(service, app) {
|
|
74
|
+
service.validators.password = require('./passwordValidator.js')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
module.exports = definition
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@live-change/password-authentication-service",
|
|
3
|
+
"version": "0.2.5",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "NODE_ENV=test tape tests/*"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/live-change/live-change-services.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/live-change/live-change-services/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/live-change/live-change-services",
|
|
18
|
+
"author": {
|
|
19
|
+
"email": "michal@laszczewski.pl",
|
|
20
|
+
"name": "Michał Łaszczewski",
|
|
21
|
+
"url": "https://www.viamage.com/"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@live-change/framework": "^0.5.7",
|
|
25
|
+
"nodemailer": "^6.7.2"
|
|
26
|
+
},
|
|
27
|
+
"gitHead": "7691357c7569a18373668691eb6a81a9e161194d"
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module.exports = (settings) => (pass) => {
|
|
2
|
+
if(!pass) return
|
|
3
|
+
let digits = /\d/.test(pass)
|
|
4
|
+
let lower = /[a-z]/.test(pass)
|
|
5
|
+
let upper = /[A-Z]/.test(pass)
|
|
6
|
+
let safe = pass.length >= 8 && digits && lower && upper
|
|
7
|
+
if (pass.length >= 15) safe = true
|
|
8
|
+
if (!safe) return "unsafePassword"
|
|
9
|
+
}
|