summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Carstairs <jcarstairs@scottlogic.com>2024-01-22 13:12:54 +0000
committerJoe Carstairs <jcarstairs@scottlogic.com>2024-01-29 10:51:49 +0000
commitde0c6a4c5d954daf0954539e034947c83086327b (patch)
tree7288dc8de346043354f7378902de268c26c476e7
parentc6cbf9a32b58c5092892932d879a8b2963a19f08 (diff)
Fixes adding an authenticator
-rw-r--r--api/auth/_verifyRegistrationResponse.ts12
-rw-r--r--api/db/_addAuthenticator.ts16
-rw-r--r--api/types/Authenticator.d.ts4
3 files changed, 16 insertions, 16 deletions
diff --git a/api/auth/_verifyRegistrationResponse.ts b/api/auth/_verifyRegistrationResponse.ts
index cf74ea5..66af079 100644
--- a/api/auth/_verifyRegistrationResponse.ts
+++ b/api/auth/_verifyRegistrationResponse.ts
@@ -37,14 +37,12 @@ export default async function verifyRegistrationResponse(
return false;
}
- const textDecoder = new TextDecoder();
-
const authenticator: Authenticator = {
- id: textDecoder.decode(verification.registrationInfo.credentialID),
+ id: verification.registrationInfo.credentialID,
backedUp: verification.registrationInfo.credentialBackedUp,
counter: verification.registrationInfo.counter,
deviceType: verification.registrationInfo.credentialDeviceType,
- publicKey: textDecoder.decode(verification.registrationInfo.credentialPublicKey),
+ publicKey: verification.registrationInfo.credentialPublicKey,
type: verification.registrationInfo.credentialType,
userId: newUser.id,
@@ -57,6 +55,8 @@ export default async function verifyRegistrationResponse(
transports: verification.registrationInfo['transports'] ?? [],
};
- addUser(newUser);
- addAuthenticator(authenticator);
+ await addUser(newUser);
+ await addAuthenticator(authenticator);
+
+ return true;
}
diff --git a/api/db/_addAuthenticator.ts b/api/db/_addAuthenticator.ts
index 9df50da..d7b7512 100644
--- a/api/db/_addAuthenticator.ts
+++ b/api/db/_addAuthenticator.ts
@@ -10,19 +10,19 @@ export default async function addAuthenticator(authenticator: Authenticator) {
${AUTHENTICATORS.fields.backedUp},
${AUTHENTICATORS.fields.counter},
${AUTHENTICATORS.fields.deviceType},
- ${AUTHENTICATORS.fields.publicKey}
+ ${AUTHENTICATORS.fields.publicKey},
${AUTHENTICATORS.fields.transports},
${AUTHENTICATORS.fields.type},
${AUTHENTICATORS.fields.userId}
) VALUES (
- ${authenticator.id},
- ${authenticator.backedUp},
+ '{ ${authenticator.id.toString()} }',
+ ${authenticator.backedUp ? 'TRUE' : 'FALSE'},
${authenticator.counter},
- ${authenticator.deviceType},
- ${authenticator.publicKey}
- { ${authenticator.transports.join(', ')} },
- ${authenticator.type},
- ${authenticator.userId}
+ '${authenticator.deviceType}',
+ '{ ${authenticator.publicKey.toString()} }',
+ '{ ${authenticator.transports.join(',')} }',
+ '${authenticator.type}',
+ '${authenticator.userId}'
);
`;
diff --git a/api/types/Authenticator.d.ts b/api/types/Authenticator.d.ts
index c56189d..54de5ee 100644
--- a/api/types/Authenticator.d.ts
+++ b/api/types/Authenticator.d.ts
@@ -1,11 +1,11 @@
import User from './User';
type Authenticator = {
- id: string,
+ id: Uint8Array,
backedUp: boolean,
counter: number,
deviceType: string,
- publicKey: string,
+ publicKey: Uint8Array,
type: 'public-key',
transports: AuthenticatorTransport[],
userId: User['id'],