update user schema, webauthn bug fix
This commit is contained in:
@@ -17,7 +17,7 @@ export async function mailProxyRoutes(fastify: FastifyInstance) {
|
||||
const input = req.body as ProxyRequest;
|
||||
|
||||
try {
|
||||
const tokens = await getOutlookTokens(input.email);
|
||||
const tokens = await getOutlookTokens(input.id);
|
||||
if (!tokens) return res.code(404).send({ error: "resource not found" });
|
||||
|
||||
const result = await axios({
|
||||
|
||||
@@ -18,7 +18,7 @@ export const mailModel = mongoose.model(
|
||||
);
|
||||
|
||||
const proxyRequest = z.object({
|
||||
email: z.string().email(),
|
||||
id: z.string(),
|
||||
url: z.string(),
|
||||
method: z.enum(["GET", "POST", "PATCH", "DELETE"]),
|
||||
body: z.any(),
|
||||
|
||||
@@ -28,7 +28,7 @@ const userSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
passKeys: [],
|
||||
passKeys: [new mongoose.Schema({}, { _id: false, strict: false })],
|
||||
challenge: new mongoose.Schema(
|
||||
{
|
||||
value: String,
|
||||
|
||||
@@ -73,7 +73,7 @@ export async function getUploadUrlMultiPart(key: string, fileSize: number) {
|
||||
export async function completeMultiPartUpload(
|
||||
key: string,
|
||||
uploadId: string,
|
||||
parts: { ETag: string; PartNumber: number }[]
|
||||
parts: { ETag?: string; PartNumber?: number }[]
|
||||
) {
|
||||
const command = new CompleteMultipartUploadCommand({
|
||||
Key: key,
|
||||
|
||||
@@ -51,8 +51,10 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
|
||||
userName: email,
|
||||
attestationType: "none",
|
||||
excludeCredentials: userInDB.passKeys.map((cred) => ({
|
||||
// @ts-ignore
|
||||
id: cred.credentialID,
|
||||
type: "public-key",
|
||||
// @ts-ignore
|
||||
transports: cred.transports,
|
||||
})),
|
||||
});
|
||||
@@ -96,7 +98,7 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
|
||||
properties: {
|
||||
email: { type: "string" },
|
||||
code: { type: "string" },
|
||||
attestationResponse: { type: "object" },
|
||||
attestationResponse: { type: "object", additionalProperties: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -174,8 +176,10 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
|
||||
await generateAuthenticationOptions({
|
||||
rpID,
|
||||
allowCredentials: userInDB.passKeys.map((cred) => ({
|
||||
// @ts-ignore
|
||||
id: cred.credentialID,
|
||||
type: "public-key",
|
||||
// @ts-ignore
|
||||
transports: cred.transports,
|
||||
})),
|
||||
userVerification: "preferred",
|
||||
@@ -218,6 +222,7 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
|
||||
|
||||
try {
|
||||
const credential = userInDB.passKeys.find(
|
||||
// @ts-ignore
|
||||
(cred) => cred.credentialID === assertionResponse.id
|
||||
);
|
||||
|
||||
@@ -230,12 +235,14 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
|
||||
expectedChallenge: userInDB.challenge.value as string,
|
||||
expectedRPID: rpID,
|
||||
expectedOrigin: origin,
|
||||
// @ts-ignore
|
||||
credential: credential,
|
||||
});
|
||||
|
||||
if (!verification.verified)
|
||||
return res.code(400).send({ error: "Authentication failed" });
|
||||
|
||||
// @ts-ignore
|
||||
credential.counter = verification.authenticationInfo.newCounter;
|
||||
|
||||
const newSession = await createSession(
|
||||
|
||||
Reference in New Issue
Block a user