@objectstack/plugin-auth 7.0.0 → 7.1.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 +50 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1696,6 +1696,56 @@ var AuthPlugin = class {
|
|
|
1696
1696
|
return c.json({ success: false, error: { code: "internal", message: err.message } }, 500);
|
|
1697
1697
|
}
|
|
1698
1698
|
});
|
|
1699
|
+
rawApp.post(`${basePath}/sys-oauth-application/register`, async (c) => {
|
|
1700
|
+
try {
|
|
1701
|
+
let body = {};
|
|
1702
|
+
try {
|
|
1703
|
+
body = await c.req.json();
|
|
1704
|
+
} catch {
|
|
1705
|
+
body = {};
|
|
1706
|
+
}
|
|
1707
|
+
const name = body?.name;
|
|
1708
|
+
const redirectUrlsInput = body?.redirectURLs;
|
|
1709
|
+
const type = body?.type;
|
|
1710
|
+
if (typeof name !== "string" || name.trim().length === 0) {
|
|
1711
|
+
return c.json({ success: false, error: { code: "invalid_request", message: "name is required" } }, 400);
|
|
1712
|
+
}
|
|
1713
|
+
if (typeof redirectUrlsInput !== "string" || redirectUrlsInput.trim().length === 0) {
|
|
1714
|
+
return c.json({ success: false, error: { code: "invalid_request", message: "redirectURLs is required" } }, 400);
|
|
1715
|
+
}
|
|
1716
|
+
const redirectUris = redirectUrlsInput.split(/[\r\n]+/).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
1717
|
+
if (redirectUris.length === 0) {
|
|
1718
|
+
return c.json({ success: false, error: { code: "invalid_request", message: "redirectURLs must contain at least one URL" } }, 400);
|
|
1719
|
+
}
|
|
1720
|
+
const allowedTypes = /* @__PURE__ */ new Set(["web", "native", "user-agent-based"]);
|
|
1721
|
+
const safeType = typeof type === "string" && allowedTypes.has(type) ? type : "web";
|
|
1722
|
+
const authApi = await this.authManager.getApi();
|
|
1723
|
+
if (!authApi?.createOAuthClient) {
|
|
1724
|
+
return c.json({ success: false, error: { code: "unavailable", message: "OIDC provider is not enabled on this environment" } }, 503);
|
|
1725
|
+
}
|
|
1726
|
+
let result;
|
|
1727
|
+
try {
|
|
1728
|
+
result = await authApi.createOAuthClient({
|
|
1729
|
+
body: {
|
|
1730
|
+
client_name: name.trim(),
|
|
1731
|
+
redirect_uris: redirectUris,
|
|
1732
|
+
type: safeType
|
|
1733
|
+
},
|
|
1734
|
+
headers: c.req.raw.headers
|
|
1735
|
+
});
|
|
1736
|
+
} catch (err) {
|
|
1737
|
+
const status = typeof err?.status === "number" ? err.status : 500;
|
|
1738
|
+
const code = err?.body?.error ?? "oauth_register_failed";
|
|
1739
|
+
const message = err?.body?.error_description ?? err?.message ?? "Unable to register OAuth client";
|
|
1740
|
+
return c.json({ success: false, error: { code, message } }, status);
|
|
1741
|
+
}
|
|
1742
|
+
return c.json({ success: true, data: { client: result } });
|
|
1743
|
+
} catch (error) {
|
|
1744
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
1745
|
+
ctx.logger.error("[AuthPlugin] sys-oauth-application/register failed", err);
|
|
1746
|
+
return c.json({ success: false, error: { code: "internal", message: err.message } }, 500);
|
|
1747
|
+
}
|
|
1748
|
+
});
|
|
1699
1749
|
rawApp.all(`${basePath}/*`, async (c) => {
|
|
1700
1750
|
try {
|
|
1701
1751
|
const response = await this.authManager.handleRequest(c.req.raw);
|