diff options
author | Emma [it/its]@Rory& <root@rory.gay> | 2023-12-11 01:12:54 +0100 |
---|---|---|
committer | Emma [it/its]@Rory& <root@rory.gay> | 2023-12-11 01:12:54 +0100 |
commit | 0a8ceb9e6349284e75545a01ffad608b020f78e2 (patch) | |
tree | 17a9163f963eddabf9168b0b630096b2f7535b64 /src/api/routes/auth/mfa/webauthn.ts | |
parent | Prettier: use editorconfig (diff) | |
download | server-dev/emma-refactors.tar.xz |
Actually run prettier dev/emma-refactors
Diffstat (limited to 'src/api/routes/auth/mfa/webauthn.ts')
-rw-r--r-- | src/api/routes/auth/mfa/webauthn.ts | 48 |
1 files changed, 14 insertions, 34 deletions
diff --git a/src/api/routes/auth/mfa/webauthn.ts b/src/api/routes/auth/mfa/webauthn.ts index b58d2944..c1a7ddb9 100644 --- a/src/api/routes/auth/mfa/webauthn.ts +++ b/src/api/routes/auth/mfa/webauthn.ts @@ -17,14 +17,7 @@ */ import { route } from "@spacebar/api"; -import { - generateToken, - SecurityKey, - User, - verifyWebAuthnToken, - WebAuthn, - WebAuthnTotpSchema, -} from "@spacebar/util"; +import { generateToken, SecurityKey, User, verifyWebAuthnToken, WebAuthn, WebAuthnTotpSchema } from "@spacebar/util"; import { Request, Response, Router } from "express"; import { ExpectedAssertionResult } from "fido2-lib"; import { HTTPError } from "lambert-server"; @@ -65,46 +58,33 @@ router.post( }); const ret = await verifyWebAuthnToken(ticket); - if (!ret) - throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008); + if (!ret) throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008); await User.update({ id: user.id }, { totp_last_ticket: "" }); const clientAttestationResponse = JSON.parse(code); - if (!clientAttestationResponse.rawId) - throw new HTTPError("Missing rawId", 400); + if (!clientAttestationResponse.rawId) throw new HTTPError("Missing rawId", 400); - clientAttestationResponse.rawId = toArrayBuffer( - Buffer.from(clientAttestationResponse.rawId, "base64url"), - ); + clientAttestationResponse.rawId = toArrayBuffer(Buffer.from(clientAttestationResponse.rawId, "base64url")); const securityKey = await SecurityKey.findOneOrFail({ where: { - key_id: Buffer.from( - clientAttestationResponse.rawId, - "base64url", - ).toString("base64"), + key_id: Buffer.from(clientAttestationResponse.rawId, "base64url").toString("base64"), }, }); const assertionExpectations: ExpectedAssertionResult = JSON.parse( - Buffer.from( - clientAttestationResponse.response.clientDataJSON, - "base64", - ).toString(), + Buffer.from(clientAttestationResponse.response.clientDataJSON, "base64").toString() ); - const authnResult = await WebAuthn.fido2.assertionResult( - clientAttestationResponse, - { - ...assertionExpectations, - factor: "second", - publicKey: securityKey.public_key, - prevCounter: securityKey.counter, - userHandle: securityKey.key_id, - }, - ); + const authnResult = await WebAuthn.fido2.assertionResult(clientAttestationResponse, { + ...assertionExpectations, + factor: "second", + publicKey: securityKey.public_key, + prevCounter: securityKey.counter, + userHandle: securityKey.key_id, + }); const counter = authnResult.authnrData.get("counter"); @@ -116,7 +96,7 @@ router.post( token: await generateToken(user.id), user_settings: user.settings, }); - }, + } ); export default router; |