add schemas to webauthn routes
This commit is contained in:
@@ -18,6 +18,7 @@ const rpName = "Quicker Permits";
|
|||||||
const origin = `http://${rpID}:3000`;
|
const origin = `http://${rpID}:3000`;
|
||||||
|
|
||||||
export async function webAuthnRoutes(fastify: FastifyInstance) {
|
export async function webAuthnRoutes(fastify: FastifyInstance) {
|
||||||
|
// Registration request
|
||||||
fastify.post<{ Body: { email: string } }>(
|
fastify.post<{ Body: { email: string } }>(
|
||||||
"/register/request",
|
"/register/request",
|
||||||
{
|
{
|
||||||
@@ -79,13 +80,28 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Registration verification
|
||||||
fastify.post<{
|
fastify.post<{
|
||||||
Body: {
|
Body: {
|
||||||
email: string;
|
email: string;
|
||||||
code: string;
|
code: string;
|
||||||
attestationResponse: RegistrationResponseJSON;
|
attestationResponse: RegistrationResponseJSON;
|
||||||
};
|
};
|
||||||
}>("/register/verify", async (req, res: FastifyReply) => {
|
}>(
|
||||||
|
"/register/verify",
|
||||||
|
{
|
||||||
|
schema: {
|
||||||
|
body: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
email: { type: "string" },
|
||||||
|
code: { type: "string" },
|
||||||
|
attestationResponse: { type: "object" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
async (req, res: FastifyReply) => {
|
||||||
const { email, code, attestationResponse } = req.body;
|
const { email, code, attestationResponse } = req.body;
|
||||||
|
|
||||||
const userInDB = await getUserByEmail(email);
|
const userInDB = await getUserByEmail(email);
|
||||||
@@ -117,7 +133,8 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
|
|||||||
|
|
||||||
userInDB.passKeys.push({
|
userInDB.passKeys.push({
|
||||||
credentialID: verification.registrationInfo.credential.id,
|
credentialID: verification.registrationInfo.credential.id,
|
||||||
credentialPublicKey: verification.registrationInfo.credential.publicKey,
|
credentialPublicKey:
|
||||||
|
verification.registrationInfo.credential.publicKey,
|
||||||
counter: verification.registrationInfo.credential.counter,
|
counter: verification.registrationInfo.credential.counter,
|
||||||
transports: attestationResponse.response.transports,
|
transports: attestationResponse.response.transports,
|
||||||
});
|
});
|
||||||
@@ -128,10 +145,22 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
return res.code(400).send({ error: error.message });
|
return res.code(400).send({ error: error.message });
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Authentication request
|
||||||
fastify.post<{ Body: { email: string } }>(
|
fastify.post<{ Body: { email: string } }>(
|
||||||
"/login/request",
|
"/login/request",
|
||||||
|
{
|
||||||
|
schema: {
|
||||||
|
body: {
|
||||||
|
type: "string",
|
||||||
|
properties: {
|
||||||
|
email: { type: "string" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const { email } = req.body;
|
const { email } = req.body;
|
||||||
|
|
||||||
@@ -161,9 +190,20 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Authentication Verification (Step 4)
|
// Authentication Verification
|
||||||
fastify.post<{ Body: { email: string; assertionResponse: any } }>(
|
fastify.post<{ Body: { email: string; assertionResponse: any } }>(
|
||||||
"/login/verify",
|
"/login/verify",
|
||||||
|
{
|
||||||
|
schema: {
|
||||||
|
body: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
email: { type: "string" },
|
||||||
|
assertionResponse: { type: "object" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const { email, assertionResponse } = req.body;
|
const { email, assertionResponse } = req.body;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user