mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 08:12:40 +10:00
another stage of client authentication
This commit is contained in:
@ -1,3 +1,27 @@
|
||||
export default defineEventHandler((h3) => {
|
||||
import clientHandler from "~/server/internal/clients/handler";
|
||||
|
||||
});
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const userId = await h3.context.session.getUserId(h3);
|
||||
if (!userId) throw createError({ statusCode: 403 });
|
||||
|
||||
const query = getQuery(h3);
|
||||
const providedClientId = query.id?.toString();
|
||||
if (!providedClientId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Provide client ID in request params as 'id'",
|
||||
});
|
||||
|
||||
const data = await clientHandler.fetchInitiateClientMetadata(
|
||||
providedClientId
|
||||
);
|
||||
if (!data)
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: "Request not found.",
|
||||
});
|
||||
|
||||
await clientHandler.attachUserId(providedClientId, userId);
|
||||
|
||||
return data;
|
||||
});
|
||||
|
||||
@ -1,3 +1,20 @@
|
||||
export default defineEventHandler((h3) => {
|
||||
import clientHandler from "~/server/internal/clients/handler";
|
||||
|
||||
});
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const userId = await h3.context.session.getUserId(h3);
|
||||
if (!userId) throw createError({ statusCode: 403 });
|
||||
|
||||
const body = await readBody(h3);
|
||||
const clientId = await body.id;
|
||||
|
||||
const data = await clientHandler.fetchInitiateClientMetadata(clientId);
|
||||
if (!data)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid or expired client ID.",
|
||||
});
|
||||
|
||||
const token = await clientHandler.generateAuthToken(clientId);
|
||||
|
||||
return `drop://handshake/${clientId}/${token}`;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user