@things-factory/auth-base 7.0.1-rc.8 → 7.0.2
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/client/actions/auth.ts +3 -3
- package/dist-client/actions/auth.d.ts +3 -3
- package/dist-client/actions/auth.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/middlewares/webauthn-middleware.js +35 -30
- package/dist-server/middlewares/webauthn-middleware.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/server/middlewares/webauthn-middleware.ts +52 -50
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/auth-base",
|
3
|
-
"version": "7.0.
|
3
|
+
"version": "7.0.2",
|
4
4
|
"main": "dist-server/index.js",
|
5
5
|
"browser": "dist-client/index.js",
|
6
6
|
"things-factory": true,
|
@@ -32,10 +32,10 @@
|
|
32
32
|
"dependencies": {
|
33
33
|
"@simplewebauthn/browser": "^10.0.0",
|
34
34
|
"@simplewebauthn/server": "^10.0.0",
|
35
|
-
"@things-factory/email-base": "^7.0.
|
36
|
-
"@things-factory/env": "^7.0.
|
37
|
-
"@things-factory/shell": "^7.0.
|
38
|
-
"@things-factory/utils": "^7.0.
|
35
|
+
"@things-factory/email-base": "^7.0.2",
|
36
|
+
"@things-factory/env": "^7.0.0",
|
37
|
+
"@things-factory/shell": "^7.0.2",
|
38
|
+
"@things-factory/utils": "^7.0.0",
|
39
39
|
"@types/webappsec-credential-management": "^0.6.8",
|
40
40
|
"jsonwebtoken": "^9.0.0",
|
41
41
|
"koa-passport": "^6.0.0",
|
@@ -46,5 +46,5 @@
|
|
46
46
|
"passport-jwt": "^4.0.0",
|
47
47
|
"passport-local": "^1.0.0"
|
48
48
|
},
|
49
|
-
"gitHead": "
|
49
|
+
"gitHead": "19f0e3097a5b583831ae530d8ff4138ca50d1619"
|
50
50
|
}
|
@@ -7,10 +7,7 @@ import { User } from '../service/user/user'
|
|
7
7
|
import { AuthError } from '../errors/auth-error'
|
8
8
|
|
9
9
|
import { WebAuthCredential } from '../service/web-auth-credential/web-auth-credential'
|
10
|
-
import {
|
11
|
-
verifyRegistrationResponse,
|
12
|
-
verifyAuthenticationResponse
|
13
|
-
} from '@simplewebauthn/server'
|
10
|
+
import { verifyRegistrationResponse, verifyAuthenticationResponse } from '@simplewebauthn/server'
|
14
11
|
|
15
12
|
import { AuthenticatorAssertionResponse } from '@simplewebauthn/types'
|
16
13
|
|
@@ -32,7 +29,7 @@ passport.use(
|
|
32
29
|
|
33
30
|
if (verification.verified) {
|
34
31
|
const { registrationInfo } = verification
|
35
|
-
const publicKey = Buffer.from(registrationInfo.credentialPublicKey).toString('base64')
|
32
|
+
const publicKey = Buffer.from(registrationInfo.credentialPublicKey).toString('base64')
|
36
33
|
|
37
34
|
if (user) {
|
38
35
|
const webAuthRepository = getRepository(WebAuthCredential)
|
@@ -56,47 +53,52 @@ passport.use(
|
|
56
53
|
passport.use(
|
57
54
|
'webauthn-login',
|
58
55
|
new CustomStrategy(async (context, done) => {
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
const credential = await getRepository(WebAuthCredential).findOne({
|
69
|
-
where: {
|
70
|
-
credentialId: assertionResponse.id
|
56
|
+
try {
|
57
|
+
const { body, session, origin, hostname } = context as any
|
58
|
+
|
59
|
+
const challenge = session.challenge
|
60
|
+
|
61
|
+
const assertionResponse = body as {
|
62
|
+
id: string
|
63
|
+
response: AuthenticatorAssertionResponse
|
71
64
|
}
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
expectedRPID: hostname,
|
83
|
-
requireUserVerification: false,
|
84
|
-
authenticator: {
|
85
|
-
credentialID: credential.credentialId,
|
86
|
-
credentialPublicKey: new Uint8Array(Buffer.from(credential.publicKey, 'base64')),
|
87
|
-
counter: credential.counter
|
65
|
+
|
66
|
+
const credential = await getRepository(WebAuthCredential).findOne({
|
67
|
+
where: {
|
68
|
+
credentialId: assertionResponse.id
|
69
|
+
},
|
70
|
+
relations: ['user']
|
71
|
+
})
|
72
|
+
|
73
|
+
if (!credential) {
|
74
|
+
return done(null, false)
|
88
75
|
}
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
76
|
+
|
77
|
+
const verification = await verifyAuthenticationResponse({
|
78
|
+
response: body,
|
79
|
+
expectedChallenge: challenge,
|
80
|
+
expectedOrigin: origin,
|
81
|
+
expectedRPID: hostname,
|
82
|
+
requireUserVerification: false,
|
83
|
+
authenticator: {
|
84
|
+
credentialID: credential.credentialId,
|
85
|
+
credentialPublicKey: new Uint8Array(Buffer.from(credential.publicKey, 'base64')),
|
86
|
+
counter: credential.counter
|
87
|
+
}
|
88
|
+
})
|
89
|
+
|
90
|
+
if (verification.verified) {
|
91
|
+
const { authenticationInfo } = verification
|
92
|
+
credential.counter = authenticationInfo.newCounter
|
93
|
+
await getRepository(WebAuthCredential).save(credential)
|
94
|
+
|
95
|
+
const user = credential.user
|
96
|
+
return done(null, user)
|
97
|
+
} else {
|
98
|
+
return done(verification, false)
|
99
|
+
}
|
100
|
+
} catch(error) {
|
101
|
+
return done(error, false)
|
100
102
|
}
|
101
103
|
})
|
102
104
|
)
|
@@ -111,15 +113,15 @@ export function createWebAuthnMiddleware(strategy: 'webauthn-register' | 'webaut
|
|
111
113
|
throw new AuthError({
|
112
114
|
errorCode: AuthError.ERROR_CODES.AUTHN_VERIFICATION_FAILED,
|
113
115
|
detail: err
|
114
|
-
})
|
116
|
+
})
|
115
117
|
} else {
|
116
|
-
context.state.user = user
|
118
|
+
context.state.user = user
|
117
119
|
|
118
|
-
context.body = { user, verified: true }
|
120
|
+
context.body = { user, verified: true }
|
119
121
|
}
|
120
122
|
|
121
|
-
await next()
|
123
|
+
await next()
|
122
124
|
}
|
123
|
-
)(context, next)
|
124
|
-
}
|
125
|
+
)(context, next)
|
126
|
+
}
|
125
127
|
}
|