@objectstack/plugin-auth 6.5.1 → 6.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2,7 +2,6 @@
2
2
  import {
3
3
  SETUP_APP,
4
4
  SystemOverviewDashboard,
5
- SecurityOverviewDashboard,
6
5
  SetupAppTranslations
7
6
  } from "@objectstack/platform-objects/apps";
8
7
 
@@ -1335,7 +1334,7 @@ var AuthPlugin = class {
1335
1334
  // (e.g. legacy `users.view` had phone/status/active columns that do
1336
1335
  // not exist on sys_user). Schema-embedded listViews is the single
1337
1336
  // source of truth.
1338
- dashboards: [SystemOverviewDashboard, SecurityOverviewDashboard]
1337
+ dashboards: [SystemOverviewDashboard]
1339
1338
  });
1340
1339
  ctx.logger.info("Auth Plugin initialized successfully");
1341
1340
  }
@@ -1530,6 +1529,61 @@ var AuthPlugin = class {
1530
1529
  return c.json({ success: false, error: { code: "internal", message: err.message } }, 500);
1531
1530
  }
1532
1531
  });
1532
+ rawApp.post(`${basePath}/admin/oauth2/toggle-disabled`, async (c) => {
1533
+ try {
1534
+ let body = {};
1535
+ try {
1536
+ body = await c.req.json();
1537
+ } catch {
1538
+ body = {};
1539
+ }
1540
+ const clientId = body?.client_id;
1541
+ const disabled = body?.disabled;
1542
+ if (typeof clientId !== "string" || clientId.length === 0) {
1543
+ return c.json({ success: false, error: { code: "invalid_request", message: "client_id is required" } }, 400);
1544
+ }
1545
+ if (typeof disabled !== "boolean") {
1546
+ return c.json({ success: false, error: { code: "invalid_request", message: "disabled must be a boolean" } }, 400);
1547
+ }
1548
+ const authApi = await this.authManager.getApi();
1549
+ const session = await authApi.getSession({ headers: c.req.raw.headers });
1550
+ if (!session?.user?.id) {
1551
+ return c.json({ success: false, error: { code: "unauthorized", message: "Sign in first" } }, 401);
1552
+ }
1553
+ if (session.user.role !== "admin") {
1554
+ return c.json({ success: false, error: { code: "forbidden", message: "Admin role required" } }, 403);
1555
+ }
1556
+ const dataEngine = this.authManager.getDataEngine();
1557
+ if (!dataEngine) {
1558
+ return c.json({ success: false, error: { code: "unavailable", message: "Data engine unavailable" } }, 503);
1559
+ }
1560
+ const existing = await dataEngine.findOne("sys_oauth_application", {
1561
+ where: { client_id: clientId }
1562
+ });
1563
+ if (!existing) {
1564
+ return c.json({ success: false, error: { code: "not_found", message: "OAuth client not found" } }, 404);
1565
+ }
1566
+ const updated = await dataEngine.update("sys_oauth_application", {
1567
+ id: existing.id,
1568
+ disabled,
1569
+ updated_at: new Date(Math.floor(Date.now() / 1e3) * 1e3)
1570
+ });
1571
+ if (!updated) {
1572
+ return c.json({ success: false, error: { code: "internal", message: "Unable to update OAuth client" } }, 500);
1573
+ }
1574
+ return c.json({
1575
+ success: true,
1576
+ data: {
1577
+ client_id: clientId,
1578
+ disabled
1579
+ }
1580
+ });
1581
+ } catch (error) {
1582
+ const err = error instanceof Error ? error : new Error(String(error));
1583
+ ctx.logger.error("[AuthPlugin] toggle-disabled failed", err);
1584
+ return c.json({ success: false, error: { code: "internal", message: err.message } }, 500);
1585
+ }
1586
+ });
1533
1587
  rawApp.all(`${basePath}/*`, async (c) => {
1534
1588
  try {
1535
1589
  const response = await this.authManager.handleRequest(c.req.raw);