mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 00:02:37 +10:00
handshakes
This commit is contained in:
@ -12,7 +12,7 @@ export default defineEventHandler(async (h3) => {
|
||||
statusMessage: "Provide client ID in request params as 'id'",
|
||||
});
|
||||
|
||||
const data = await clientHandler.fetchInitiateClientMetadata(
|
||||
const data = await clientHandler.fetchClientMetadata(
|
||||
providedClientId
|
||||
);
|
||||
if (!data)
|
||||
|
||||
@ -7,7 +7,7 @@ export default defineEventHandler(async (h3) => {
|
||||
const body = await readBody(h3);
|
||||
const clientId = await body.id;
|
||||
|
||||
const data = await clientHandler.fetchInitiateClientMetadata(clientId);
|
||||
const data = await clientHandler.fetchClientMetadata(clientId);
|
||||
if (!data)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
|
||||
@ -1,3 +1,46 @@
|
||||
export default defineEventHandler((h3) => {
|
||||
|
||||
})
|
||||
import clientHandler from "~/server/internal/clients/handler";
|
||||
import { useGlobalCertificateAuthority } from "~/server/plugins/ca";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const body = await readBody(h3);
|
||||
const clientId = body.clientId;
|
||||
const token = body.token;
|
||||
if (!clientId || !token)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing token or client ID from body",
|
||||
});
|
||||
|
||||
const metadata = await clientHandler.fetchClient(clientId);
|
||||
if (!metadata)
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: "Invalid client ID",
|
||||
});
|
||||
if (!metadata.authToken || !metadata.userId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Un-authorized client ID",
|
||||
});
|
||||
if (metadata.authToken !== token)
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: "Invalid token",
|
||||
});
|
||||
|
||||
const ca = useGlobalCertificateAuthority();
|
||||
const bundle = await ca.generateClientCertificate(
|
||||
clientId,
|
||||
metadata.data.name
|
||||
);
|
||||
|
||||
const client = await clientHandler.finialiseClient(clientId);
|
||||
await ca.storeClientCertificate(clientId, bundle);
|
||||
|
||||
return {
|
||||
private: bundle.priv,
|
||||
public: bundle.pub,
|
||||
certificate: bundle.cert,
|
||||
id: client.id,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user