mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 00:02:37 +10:00
feat: add ability to review and revoke clients
This commit is contained in:
@ -64,13 +64,13 @@ export class CertificateAuthority {
|
||||
|
||||
async fetchClientCertificate(clientId: string) {
|
||||
const isBlacklist = await this.certificateStore.checkBlacklistCertificate(
|
||||
clientId
|
||||
`client:${clientId}`
|
||||
);
|
||||
if (isBlacklist) return undefined;
|
||||
return await this.certificateStore.fetch(`client:${clientId}`);
|
||||
}
|
||||
|
||||
async blacklistClient(clientId: string) {
|
||||
await this.certificateStore.blacklistCertificate(clientId);
|
||||
await this.certificateStore.blacklistCertificate(`client:${clientId}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ import { EventHandlerRequest, H3Event } from "h3";
|
||||
import droplet from "@drop-oss/droplet";
|
||||
import prisma from "../db/database";
|
||||
import { useCertificateAuthority } from "~/server/plugins/ca";
|
||||
import moment from "moment";
|
||||
|
||||
export type EventHandlerFunction<T> = (
|
||||
h3: H3Event<EventHandlerRequest>,
|
||||
@ -122,7 +123,7 @@ export function defineClientEventHandler<T>(handler: EventHandlerFunction<T>) {
|
||||
fetchUser,
|
||||
};
|
||||
|
||||
prisma.client.update({
|
||||
await prisma.client.update({
|
||||
where: { id: clientId },
|
||||
data: { lastConnected: new Date() },
|
||||
});
|
||||
|
||||
@ -2,6 +2,7 @@ import { v4 as uuidv4 } from "uuid";
|
||||
import { CertificateBundle } from "./ca";
|
||||
import prisma from "../db/database";
|
||||
import { Platform } from "@prisma/client";
|
||||
import { useCertificateAuthority } from "~/server/plugins/ca";
|
||||
|
||||
export interface ClientMetadata {
|
||||
name: string;
|
||||
@ -82,6 +83,17 @@ export class ClientHandler {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async removeClient(id: string) {
|
||||
const ca = useCertificateAuthority();
|
||||
await ca.blacklistClient(id);
|
||||
|
||||
await prisma.client.delete({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const clientHandler = new ClientHandler();
|
||||
|
||||
Reference in New Issue
Block a user