@things-factory/auth-base 7.0.1-rc.8 → 7.0.1-rc.9

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.8",
3
+ "version": "7.0.1-rc.9",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -46,5 +46,5 @@
46
46
  "passport-jwt": "^4.0.0",
47
47
  "passport-local": "^1.0.0"
48
48
  },
49
- "gitHead": "cf1d0f8f261c73eadecb517fc6c82e92e50d6caf"
49
+ "gitHead": "70c4b8737f2ccb632699f31a92173401624ee9f7"
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)
@@ -64,11 +61,12 @@ passport.use(
64
61
  id: string
65
62
  response: AuthenticatorAssertionResponse
66
63
  }
67
-
64
+
68
65
  const credential = await getRepository(WebAuthCredential).findOne({
69
66
  where: {
70
67
  credentialId: assertionResponse.id
71
- }
68
+ },
69
+ relations: ['user']
72
70
  })
73
71
 
74
72
  if (!credential) {
@@ -93,7 +91,7 @@ passport.use(
93
91
  credential.counter = authenticationInfo.newCounter
94
92
  await getRepository(WebAuthCredential).save(credential)
95
93
 
96
- const user = await getRepository(User).findOne({ where: { email: body.email } })
94
+ const user = credential.user
97
95
  return done(null, user)
98
96
  } else {
99
97
  return done(verification, false)
@@ -111,15 +109,15 @@ export function createWebAuthnMiddleware(strategy: 'webauthn-register' | 'webaut
111
109
  throw new AuthError({
112
110
  errorCode: AuthError.ERROR_CODES.AUTHN_VERIFICATION_FAILED,
113
111
  detail: err
114
- });
112
+ })
115
113
  } else {
116
- context.state.user = user;
114
+ context.state.user = user
117
115
 
118
- context.body = { user, verified: true };
116
+ context.body = { user, verified: true }
119
117
  }
120
118
 
121
- await next();
119
+ await next()
122
120
  }
123
- )(context, next);
124
- };
121
+ )(context, next)
122
+ }
125
123
  }