summary refs log tree commit diff
path: root/src/api/routes/auth/mfa
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/routes/auth/mfa')
-rw-r--r--src/api/routes/auth/mfa/totp.ts8
-rw-r--r--src/api/routes/auth/mfa/webauthn.ts48
2 files changed, 16 insertions, 40 deletions
diff --git a/src/api/routes/auth/mfa/totp.ts b/src/api/routes/auth/mfa/totp.ts

index 4df408f9..956993b3 100644 --- a/src/api/routes/auth/mfa/totp.ts +++ b/src/api/routes/auth/mfa/totp.ts
@@ -59,11 +59,7 @@ router.post( if (!backup) { const ret = verifyToken(user.totp_secret || "", code); - if (!ret || ret.delta != 0) - throw new HTTPError( - req.t("auth:login.INVALID_TOTP_CODE"), - 60008, - ); + if (!ret || ret.delta != 0) throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008); } else { backup.consumed = true; await backup.save(); @@ -75,7 +71,7 @@ router.post( token: await generateToken(user.id), settings: { ...user.settings, index: undefined }, }); - }, + } ); export default router; 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;