@objectstack/plugin-auth 6.5.1 → 6.6.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.js +55 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1530,6 +1530,61 @@ var AuthPlugin = class {
|
|
|
1530
1530
|
return c.json({ success: false, error: { code: "internal", message: err.message } }, 500);
|
|
1531
1531
|
}
|
|
1532
1532
|
});
|
|
1533
|
+
rawApp.post(`${basePath}/admin/oauth2/toggle-disabled`, async (c) => {
|
|
1534
|
+
try {
|
|
1535
|
+
let body = {};
|
|
1536
|
+
try {
|
|
1537
|
+
body = await c.req.json();
|
|
1538
|
+
} catch {
|
|
1539
|
+
body = {};
|
|
1540
|
+
}
|
|
1541
|
+
const clientId = body?.client_id;
|
|
1542
|
+
const disabled = body?.disabled;
|
|
1543
|
+
if (typeof clientId !== "string" || clientId.length === 0) {
|
|
1544
|
+
return c.json({ success: false, error: { code: "invalid_request", message: "client_id is required" } }, 400);
|
|
1545
|
+
}
|
|
1546
|
+
if (typeof disabled !== "boolean") {
|
|
1547
|
+
return c.json({ success: false, error: { code: "invalid_request", message: "disabled must be a boolean" } }, 400);
|
|
1548
|
+
}
|
|
1549
|
+
const authApi = await this.authManager.getApi();
|
|
1550
|
+
const session = await authApi.getSession({ headers: c.req.raw.headers });
|
|
1551
|
+
if (!session?.user?.id) {
|
|
1552
|
+
return c.json({ success: false, error: { code: "unauthorized", message: "Sign in first" } }, 401);
|
|
1553
|
+
}
|
|
1554
|
+
if (session.user.role !== "admin") {
|
|
1555
|
+
return c.json({ success: false, error: { code: "forbidden", message: "Admin role required" } }, 403);
|
|
1556
|
+
}
|
|
1557
|
+
const dataEngine = this.authManager.getDataEngine();
|
|
1558
|
+
if (!dataEngine) {
|
|
1559
|
+
return c.json({ success: false, error: { code: "unavailable", message: "Data engine unavailable" } }, 503);
|
|
1560
|
+
}
|
|
1561
|
+
const existing = await dataEngine.findOne("sys_oauth_application", {
|
|
1562
|
+
where: { client_id: clientId }
|
|
1563
|
+
});
|
|
1564
|
+
if (!existing) {
|
|
1565
|
+
return c.json({ success: false, error: { code: "not_found", message: "OAuth client not found" } }, 404);
|
|
1566
|
+
}
|
|
1567
|
+
const updated = await dataEngine.update("sys_oauth_application", {
|
|
1568
|
+
id: existing.id,
|
|
1569
|
+
disabled,
|
|
1570
|
+
updated_at: new Date(Math.floor(Date.now() / 1e3) * 1e3)
|
|
1571
|
+
});
|
|
1572
|
+
if (!updated) {
|
|
1573
|
+
return c.json({ success: false, error: { code: "internal", message: "Unable to update OAuth client" } }, 500);
|
|
1574
|
+
}
|
|
1575
|
+
return c.json({
|
|
1576
|
+
success: true,
|
|
1577
|
+
data: {
|
|
1578
|
+
client_id: clientId,
|
|
1579
|
+
disabled
|
|
1580
|
+
}
|
|
1581
|
+
});
|
|
1582
|
+
} catch (error) {
|
|
1583
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
1584
|
+
ctx.logger.error("[AuthPlugin] toggle-disabled failed", err);
|
|
1585
|
+
return c.json({ success: false, error: { code: "internal", message: err.message } }, 500);
|
|
1586
|
+
}
|
|
1587
|
+
});
|
|
1533
1588
|
rawApp.all(`${basePath}/*`, async (c) => {
|
|
1534
1589
|
try {
|
|
1535
1590
|
const response = await this.authManager.handleRequest(c.req.raw);
|