Revoke devices through Cloudflare API
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
approveDeviceDocument,
|
||||
deviceListDocument,
|
||||
registerDeviceDocument,
|
||||
revokeDeviceDocument,
|
||||
} from "./devices.js";
|
||||
import {
|
||||
PluginRegistrySchemaError,
|
||||
@@ -130,6 +131,44 @@ export async function handleRequest(request: Request, env: Env): Promise<Respons
|
||||
},
|
||||
);
|
||||
}
|
||||
if (url.pathname === "/api/devices/revoke") {
|
||||
return withAuthenticatedApiControls(
|
||||
request,
|
||||
env,
|
||||
"devices.revoke",
|
||||
["POST"],
|
||||
async (context) => {
|
||||
try {
|
||||
return jsonResponse(await revokeDeviceDocument(request, env, context), 200, {
|
||||
"Cache-Control": "no-store",
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof DevicePermissionError) {
|
||||
return jsonResponse(
|
||||
{ error: "device_revocation_forbidden" },
|
||||
403,
|
||||
{ "Cache-Control": "no-store" },
|
||||
);
|
||||
}
|
||||
if (error instanceof DeviceSchemaError) {
|
||||
return jsonResponse(
|
||||
{ error: "invalid_device_revocation" },
|
||||
400,
|
||||
{ "Cache-Control": "no-store" },
|
||||
);
|
||||
}
|
||||
if (error instanceof DevicePersistenceError) {
|
||||
return jsonResponse(
|
||||
{ error: "device_revocation_failed" },
|
||||
500,
|
||||
{ "Cache-Control": "no-store" },
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
if (url.pathname === "/api/plugins/signing-keys") {
|
||||
return withPublicApiControls(request, env, "plugins.signing_keys", ["GET"], () =>
|
||||
handlePublicSigningKeys(env),
|
||||
|
||||
Reference in New Issue
Block a user