@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.mjs
CHANGED
|
@@ -1651,6 +1651,56 @@ var AuthPlugin = class {
|
|
|
1651
1651
|
return c.json({ success: false, error: { code: "internal", message: err.message } }, 500);
|
|
1652
1652
|
}
|
|
1653
1653
|
});
|
|
1654
|
+
rawApp.post(`${basePath}/sys-oauth-application/register`, async (c) => {
|
|
1655
|
+
try {
|
|
1656
|
+
let body = {};
|
|
1657
|
+
try {
|
|
1658
|
+
body = await c.req.json();
|
|
1659
|
+
} catch {
|
|
1660
|
+
body = {};
|
|
1661
|
+
}
|
|
1662
|
+
const name = body?.name;
|
|
1663
|
+
const redirectUrlsInput = body?.redirectURLs;
|
|
1664
|
+
const type = body?.type;
|
|
1665
|
+
if (typeof name !== "string" || name.trim().length === 0) {
|
|
1666
|
+
return c.json({ success: false, error: { code: "invalid_request", message: "name is required" } }, 400);
|
|
1667
|
+
}
|
|
1668
|
+
if (typeof redirectUrlsInput !== "string" || redirectUrlsInput.trim().length === 0) {
|
|
1669
|
+
return c.json({ success: false, error: { code: "invalid_request", message: "redirectURLs is required" } }, 400);
|
|
1670
|
+
}
|
|
1671
|
+
const redirectUris = redirectUrlsInput.split(/[\r\n]+/).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
1672
|
+
if (redirectUris.length === 0) {
|
|
1673
|
+
return c.json({ success: false, error: { code: "invalid_request", message: "redirectURLs must contain at least one URL" } }, 400);
|
|
1674
|
+
}
|
|
1675
|
+
const allowedTypes = /* @__PURE__ */ new Set(["web", "native", "user-agent-based"]);
|
|
1676
|
+
const safeType = typeof type === "string" && allowedTypes.has(type) ? type : "web";
|
|
1677
|
+
const authApi = await this.authManager.getApi();
|
|
1678
|
+
if (!authApi?.createOAuthClient) {
|
|
1679
|
+
return c.json({ success: false, error: { code: "unavailable", message: "OIDC provider is not enabled on this environment" } }, 503);
|
|
1680
|
+
}
|
|
1681
|
+
let result;
|
|
1682
|
+
try {
|
|
1683
|
+
result = await authApi.createOAuthClient({
|
|
1684
|
+
body: {
|
|
1685
|
+
client_name: name.trim(),
|
|
1686
|
+
redirect_uris: redirectUris,
|
|
1687
|
+
type: safeType
|
|
1688
|
+
},
|
|
1689
|
+
headers: c.req.raw.headers
|
|
1690
|
+
});
|
|
1691
|
+
} catch (err) {
|
|
1692
|
+
const status = typeof err?.status === "number" ? err.status : 500;
|
|
1693
|
+
const code = err?.body?.error ?? "oauth_register_failed";
|
|
1694
|
+
const message = err?.body?.error_description ?? err?.message ?? "Unable to register OAuth client";
|
|
1695
|
+
return c.json({ success: false, error: { code, message } }, status);
|
|
1696
|
+
}
|
|
1697
|
+
return c.json({ success: true, data: { client: result } });
|
|
1698
|
+
} catch (error) {
|
|
1699
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
1700
|
+
ctx.logger.error("[AuthPlugin] sys-oauth-application/register failed", err);
|
|
1701
|
+
return c.json({ success: false, error: { code: "internal", message: err.message } }, 500);
|
|
1702
|
+
}
|
|
1703
|
+
});
|
|
1654
1704
|
rawApp.all(`${basePath}/*`, async (c) => {
|
|
1655
1705
|
try {
|
|
1656
1706
|
const response = await this.authManager.handleRequest(c.req.raw);
|