@things-factory/auth-base 7.0.1-rc.9 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/auth-base",
3
- "version": "7.0.1-rc.9",
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.1-rc.8",
36
- "@things-factory/env": "^7.0.1-rc.8",
37
- "@things-factory/shell": "^7.0.1-rc.8",
38
- "@things-factory/utils": "^7.0.1-rc.7",
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": "70c4b8737f2ccb632699f31a92173401624ee9f7"
49
+ "gitHead": "19f0e3097a5b583831ae530d8ff4138ca50d1619"
50
50
  }
@@ -53,48 +53,52 @@ passport.use(
53
53
  passport.use(
54
54
  'webauthn-login',
55
55
  new CustomStrategy(async (context, done) => {
56
- const { body, session, origin, hostname } = context as any
57
-
58
- const challenge = session.challenge
59
-
60
- const assertionResponse = body as {
61
- id: string
62
- response: AuthenticatorAssertionResponse
63
- }
64
-
65
- const credential = await getRepository(WebAuthCredential).findOne({
66
- where: {
67
- credentialId: assertionResponse.id
68
- },
69
- relations: ['user']
70
- })
71
-
72
- if (!credential) {
73
- return done(null, false)
74
- }
75
-
76
- const verification = await verifyAuthenticationResponse({
77
- response: body,
78
- expectedChallenge: challenge,
79
- expectedOrigin: origin,
80
- expectedRPID: hostname,
81
- requireUserVerification: false,
82
- authenticator: {
83
- credentialID: credential.credentialId,
84
- credentialPublicKey: new Uint8Array(Buffer.from(credential.publicKey, 'base64')),
85
- counter: credential.counter
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
86
64
  }
87
- })
88
-
89
- if (verification.verified) {
90
- const { authenticationInfo } = verification
91
- credential.counter = authenticationInfo.newCounter
92
- await getRepository(WebAuthCredential).save(credential)
93
-
94
- const user = credential.user
95
- return done(null, user)
96
- } else {
97
- return done(verification, false)
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)
75
+ }
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)
98
102
  }
99
103
  })
100
104
  )