cauthy-auth 0.30.0 → 0.32.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/README.md +50 -5
- package/dist/{cauthy-BXgsZ-Um.d.mts → cauthy-2jtP2LVQ.d.mts} +1 -1
- package/dist/{cauthy-CHENs452.d.ts → cauthy-CKfvvv_i.d.ts} +1 -1
- package/dist/cli.js +8 -5
- package/dist/client.d.mts +47 -6
- package/dist/client.d.ts +47 -6
- package/dist/client.js +16 -2
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +16 -2
- package/dist/client.mjs.map +1 -1
- package/dist/express.d.mts +2 -2
- package/dist/express.d.ts +2 -2
- package/dist/fastify.d.mts +2 -2
- package/dist/fastify.d.ts +2 -2
- package/dist/hono.d.mts +2 -2
- package/dist/hono.d.ts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +64 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -21
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +2 -2
- package/dist/next.d.ts +2 -2
- package/dist/react.d.mts +339 -31
- package/dist/react.d.ts +339 -31
- package/dist/react.js +616 -225
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +610 -230
- package/dist/react.mjs.map +1 -1
- package/dist/styles.css +8 -0
- package/dist/svelte.d.mts +2 -2
- package/dist/svelte.d.ts +2 -2
- package/dist/svelte.js +16 -2
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +16 -2
- package/dist/svelte.mjs.map +1 -1
- package/dist/{system-0mHrdAgO.d.mts → system-BrrJsrFW.d.mts} +14 -0
- package/dist/{system-BIYbS7h2.d.ts → system-BvvoNs2y.d.ts} +14 -0
- package/dist/vue.d.mts +2 -2
- package/dist/vue.d.ts +2 -2
- package/dist/vue.js +16 -2
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +16 -2
- package/dist/vue.mjs.map +1 -1
- package/package.json +2 -1
package/dist/express.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
-
import { C as Cauthy } from './cauthy-
|
|
3
|
-
import { S as Session } from './system-
|
|
2
|
+
import { C as Cauthy } from './cauthy-2jtP2LVQ.mjs';
|
|
3
|
+
import { S as Session } from './system-BrrJsrFW.mjs';
|
|
4
4
|
import 'jose';
|
|
5
5
|
import './theme.mjs';
|
|
6
6
|
|
package/dist/express.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
-
import { C as Cauthy } from './cauthy-
|
|
3
|
-
import { S as Session } from './system-
|
|
2
|
+
import { C as Cauthy } from './cauthy-CKfvvv_i.js';
|
|
3
|
+
import { S as Session } from './system-BvvoNs2y.js';
|
|
4
4
|
import 'jose';
|
|
5
5
|
import './theme.js';
|
|
6
6
|
|
package/dist/fastify.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FastifyReply, FastifyPluginAsync } from 'fastify';
|
|
2
|
-
import { C as Cauthy } from './cauthy-
|
|
3
|
-
import { S as Session } from './system-
|
|
2
|
+
import { C as Cauthy } from './cauthy-2jtP2LVQ.mjs';
|
|
3
|
+
import { S as Session } from './system-BrrJsrFW.mjs';
|
|
4
4
|
import 'jose';
|
|
5
5
|
import './theme.mjs';
|
|
6
6
|
|
package/dist/fastify.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FastifyReply, FastifyPluginAsync } from 'fastify';
|
|
2
|
-
import { C as Cauthy } from './cauthy-
|
|
3
|
-
import { S as Session } from './system-
|
|
2
|
+
import { C as Cauthy } from './cauthy-CKfvvv_i.js';
|
|
3
|
+
import { S as Session } from './system-BvvoNs2y.js';
|
|
4
4
|
import 'jose';
|
|
5
5
|
import './theme.js';
|
|
6
6
|
|
package/dist/hono.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MiddlewareHandler } from 'hono';
|
|
2
|
-
import { C as Cauthy } from './cauthy-
|
|
3
|
-
import { S as Session } from './system-
|
|
2
|
+
import { C as Cauthy } from './cauthy-2jtP2LVQ.mjs';
|
|
3
|
+
import { S as Session } from './system-BrrJsrFW.mjs';
|
|
4
4
|
import 'jose';
|
|
5
5
|
import './theme.mjs';
|
|
6
6
|
|
package/dist/hono.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MiddlewareHandler } from 'hono';
|
|
2
|
-
import { C as Cauthy } from './cauthy-
|
|
3
|
-
import { S as Session } from './system-
|
|
2
|
+
import { C as Cauthy } from './cauthy-CKfvvv_i.js';
|
|
3
|
+
import { S as Session } from './system-BvvoNs2y.js';
|
|
4
4
|
import 'jose';
|
|
5
5
|
import './theme.js';
|
|
6
6
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { C as Cauthy, a as CauthyEvent, b as CauthyWebhookError, R as Resolved, V as VerifyWebhookOptions, c as createCauthy, v as verifyWebhook } from './cauthy-
|
|
2
|
-
export { A as AttributeType, C as CatalogResource, a as CauthyApiError, b as CauthyConfigError, c as CauthyOptions, d as CauthySystem, e as CheckOf, f as CheckQuestion, g as CheckResult, h as CheckRule, i as ConditionalPermission, J as JsonValue, N as NewMember, O as Organization, j as OrganizationMember, k as OrganizationRef, P as PermissionOf, l as Permitted, m as Policy, n as PolicyDefinition, o as PolicyPermission, p as PolicyRole, q as PublicSession, r as PushPolicyOptions, R as RoleOf, S as Session, s as SessionOrganization, t as SessionStatus, u as SessionUser, v as SystemKey, w as SystemOptions, x as SystemPolicy, y as can, z as createSystem, B as definePolicy, D as policySource, E as pullCatalog, F as pullPolicy, G as pushCatalog, H as pushPolicy } from './system-
|
|
1
|
+
export { C as Cauthy, a as CauthyEvent, b as CauthyWebhookError, R as Resolved, V as VerifyWebhookOptions, c as createCauthy, v as verifyWebhook } from './cauthy-2jtP2LVQ.mjs';
|
|
2
|
+
export { A as AttributeType, C as CatalogResource, a as CauthyApiError, b as CauthyConfigError, c as CauthyOptions, d as CauthySystem, e as CheckOf, f as CheckQuestion, g as CheckResult, h as CheckRule, i as ConditionalPermission, J as JsonValue, N as NewMember, O as Organization, j as OrganizationMember, k as OrganizationRef, P as PermissionOf, l as Permitted, m as Policy, n as PolicyDefinition, o as PolicyPermission, p as PolicyRole, q as PublicSession, r as PushPolicyOptions, R as RoleOf, S as Session, s as SessionOrganization, t as SessionStatus, u as SessionUser, v as SystemKey, w as SystemOptions, x as SystemPolicy, y as can, z as createSystem, B as definePolicy, D as policySource, E as pullCatalog, F as pullPolicy, G as pushCatalog, H as pushPolicy } from './system-BrrJsrFW.mjs';
|
|
3
3
|
export { CauthyTheme, ImportedTheme, PushThemeOptions, StackmythThemeOptions, StackmythTokens, ThemeFont, ThemeTexts, pushTheme, themeFromStackmyth, tokensFromStackmyth } from './theme.mjs';
|
|
4
4
|
export { A as AuthField, D as DEFAULT_PASSWORD_POLICY, F as FieldProblem, M as MIN_PASSWORD, P as PasswordClass, a as PasswordLocale, b as PasswordPolicy, c as PasswordReason, d as checkCode, e as checkEmail, f as checkName, g as checkNewPassword, h as checkPassword, i as describePasswordPolicy, j as explainPasswordProblems, p as passwordPolicyOf, k as passwordProblems } from './validate-sEXG82po.mjs';
|
|
5
5
|
import { JWTVerifyGetKey } from 'jose';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { C as Cauthy, a as CauthyEvent, b as CauthyWebhookError, R as Resolved, V as VerifyWebhookOptions, c as createCauthy, v as verifyWebhook } from './cauthy-
|
|
2
|
-
export { A as AttributeType, C as CatalogResource, a as CauthyApiError, b as CauthyConfigError, c as CauthyOptions, d as CauthySystem, e as CheckOf, f as CheckQuestion, g as CheckResult, h as CheckRule, i as ConditionalPermission, J as JsonValue, N as NewMember, O as Organization, j as OrganizationMember, k as OrganizationRef, P as PermissionOf, l as Permitted, m as Policy, n as PolicyDefinition, o as PolicyPermission, p as PolicyRole, q as PublicSession, r as PushPolicyOptions, R as RoleOf, S as Session, s as SessionOrganization, t as SessionStatus, u as SessionUser, v as SystemKey, w as SystemOptions, x as SystemPolicy, y as can, z as createSystem, B as definePolicy, D as policySource, E as pullCatalog, F as pullPolicy, G as pushCatalog, H as pushPolicy } from './system-
|
|
1
|
+
export { C as Cauthy, a as CauthyEvent, b as CauthyWebhookError, R as Resolved, V as VerifyWebhookOptions, c as createCauthy, v as verifyWebhook } from './cauthy-CKfvvv_i.js';
|
|
2
|
+
export { A as AttributeType, C as CatalogResource, a as CauthyApiError, b as CauthyConfigError, c as CauthyOptions, d as CauthySystem, e as CheckOf, f as CheckQuestion, g as CheckResult, h as CheckRule, i as ConditionalPermission, J as JsonValue, N as NewMember, O as Organization, j as OrganizationMember, k as OrganizationRef, P as PermissionOf, l as Permitted, m as Policy, n as PolicyDefinition, o as PolicyPermission, p as PolicyRole, q as PublicSession, r as PushPolicyOptions, R as RoleOf, S as Session, s as SessionOrganization, t as SessionStatus, u as SessionUser, v as SystemKey, w as SystemOptions, x as SystemPolicy, y as can, z as createSystem, B as definePolicy, D as policySource, E as pullCatalog, F as pullPolicy, G as pushCatalog, H as pushPolicy } from './system-BvvoNs2y.js';
|
|
3
3
|
export { CauthyTheme, ImportedTheme, PushThemeOptions, StackmythThemeOptions, StackmythTokens, ThemeFont, ThemeTexts, pushTheme, themeFromStackmyth, tokensFromStackmyth } from './theme.js';
|
|
4
4
|
export { A as AuthField, D as DEFAULT_PASSWORD_POLICY, F as FieldProblem, M as MIN_PASSWORD, P as PasswordClass, a as PasswordLocale, b as PasswordPolicy, c as PasswordReason, d as checkCode, e as checkEmail, f as checkName, g as checkNewPassword, h as checkPassword, i as describePasswordPolicy, j as explainPasswordProblems, p as passwordPolicyOf, k as passwordProblems } from './validate-sEXG82po.js';
|
|
5
5
|
import { JWTVerifyGetKey } from 'jose';
|
package/dist/index.js
CHANGED
|
@@ -746,6 +746,8 @@ function createSystem(given = {}) {
|
|
|
746
746
|
const envKey = env("CAUTHY_SYSTEM_KEY");
|
|
747
747
|
const key = given.key ?? (envKey ? { privateKey: envKey, keyId: env("CAUTHY_SYSTEM_KEY_ID") ?? "" } : void 0);
|
|
748
748
|
const ownSystem = given.system ?? env("CAUTHY_SYSTEM") ?? "";
|
|
749
|
+
const acceptInviteUrl = given.acceptInviteUrl ?? env("CAUTHY_ACCEPT_INVITE_URL") ?? "";
|
|
750
|
+
const inviteHeaders = /^https?:\/\//.test(acceptInviteUrl) ? { "x-cauthy-client-id": clientId, "x-cauthy-link-to": acceptInviteUrl } : {};
|
|
749
751
|
const doFetch = (...args) => (given.fetch ?? fetch)(...args);
|
|
750
752
|
const tokenEndpoint = `${issuer}/v1/oauth/token`;
|
|
751
753
|
function configured() {
|
|
@@ -788,10 +790,10 @@ function createSystem(given = {}) {
|
|
|
788
790
|
asking = void 0;
|
|
789
791
|
});
|
|
790
792
|
}
|
|
791
|
-
async function call(method, path, body) {
|
|
793
|
+
async function call(method, path, body, extra = {}) {
|
|
792
794
|
const send = async () => doFetch(`${issuer}${path}`, {
|
|
793
795
|
method,
|
|
794
|
-
headers: { authorization: `Bearer ${await token()}`, ...body === void 0 ? {} : { "content-type": "application/json" } },
|
|
796
|
+
headers: { authorization: `Bearer ${await token()}`, ...extra, ...body === void 0 ? {} : { "content-type": "application/json" } },
|
|
795
797
|
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
796
798
|
});
|
|
797
799
|
let res = await send();
|
|
@@ -802,7 +804,7 @@ function createSystem(given = {}) {
|
|
|
802
804
|
if (!res.ok) await fail(res, `${method} ${path}`);
|
|
803
805
|
return res.status === 204 ? void 0 : res.json();
|
|
804
806
|
}
|
|
805
|
-
const data = async (method, path, body) => (await call(method, path, body))?.data;
|
|
807
|
+
const data = async (method, path, body, extra) => (await call(method, path, body, extra))?.data;
|
|
806
808
|
const id = encodeURIComponent;
|
|
807
809
|
return {
|
|
808
810
|
token,
|
|
@@ -839,7 +841,8 @@ function createSystem(given = {}) {
|
|
|
839
841
|
return toMember(await data(
|
|
840
842
|
"POST",
|
|
841
843
|
`/v1/organizations/${id(orgId)}/members`,
|
|
842
|
-
{ role: m.role, user_id: m.userId, email: m.email, name: m.name, locale: m.locale, client_id: clientId }
|
|
844
|
+
{ role: m.role, user_id: m.userId, email: m.email, name: m.name, locale: m.locale, client_id: clientId },
|
|
845
|
+
inviteHeaders
|
|
843
846
|
));
|
|
844
847
|
},
|
|
845
848
|
async setRole(orgId, userId, role) {
|
|
@@ -850,7 +853,7 @@ function createSystem(given = {}) {
|
|
|
850
853
|
}
|
|
851
854
|
},
|
|
852
855
|
async invite(person) {
|
|
853
|
-
const u = await data("POST", "/v1/users", { ...person, client_id: clientId });
|
|
856
|
+
const u = await data("POST", "/v1/users", { ...person, client_id: clientId }, inviteHeaders);
|
|
854
857
|
return { id: u.id, email: u.email };
|
|
855
858
|
},
|
|
856
859
|
theme: {
|
|
@@ -1185,13 +1188,16 @@ function createCauthy(given = {}) {
|
|
|
1185
1188
|
const againCookie = `${cookieName}_again`;
|
|
1186
1189
|
const stepCookie = `${cookieName}_step`;
|
|
1187
1190
|
const doFetch = (...args) => (given.fetch ?? fetch)(...args);
|
|
1191
|
+
const iconOf = iconFor(issuer);
|
|
1188
1192
|
const key = keyOf(secret);
|
|
1189
1193
|
const pages = {
|
|
1190
1194
|
signIn: given.pages?.signIn ? localPath(given.pages.signIn, "/") : void 0,
|
|
1191
1195
|
resetPassword: given.pages?.resetPassword ? localPath(given.pages.resetPassword, "/") : void 0,
|
|
1192
|
-
verifyEmail: given.pages?.verifyEmail ? localPath(given.pages.verifyEmail, "/") : void 0
|
|
1196
|
+
verifyEmail: given.pages?.verifyEmail ? localPath(given.pages.verifyEmail, "/") : void 0,
|
|
1197
|
+
acceptInvite: given.pages?.acceptInvite ? localPath(given.pages.acceptInvite, "/") : void 0
|
|
1193
1198
|
};
|
|
1194
|
-
const
|
|
1199
|
+
const acceptInviteUrl = baseURL && pages.acceptInvite ? `${withoutTrailingSlashes(baseURL)}${pages.acceptInvite}` : void 0;
|
|
1200
|
+
const ownSystem = createSystem({ issuer, clientId, clientSecret, key: given.systemKey, system: system || void 0, acceptInviteUrl, fetch: given.fetch });
|
|
1195
1201
|
const originOf = (request) => {
|
|
1196
1202
|
if (baseURL) return withoutTrailingSlashes(baseURL);
|
|
1197
1203
|
const url = new URL(request.url);
|
|
@@ -1618,6 +1624,14 @@ function createCauthy(given = {}) {
|
|
|
1618
1624
|
for (const c of [...await write(request, s, readCookies(request.headers.get("cookie"))), ...extra]) h.append("set-cookie", c);
|
|
1619
1625
|
return json({ status: "signed_in", session: await toPublic(toSession(s)), ...more }, 200, h);
|
|
1620
1626
|
}
|
|
1627
|
+
async function loggedIn(request, data) {
|
|
1628
|
+
if (data?.mfa_required === true) {
|
|
1629
|
+
const step = { kind: "mfa", token: String(data.mfa_token ?? ""), returnTo: afterSignIn };
|
|
1630
|
+
const how = data.mfa_method === "email" ? { method: "email" } : {};
|
|
1631
|
+
return json({ status: "mfa_required", ...how }, 200, new Headers({ "set-cookie": writeCookie(stepCookie, await seal(step, await key), attrs(request, STEP_SECONDS)) }));
|
|
1632
|
+
}
|
|
1633
|
+
return signedIn(request, data);
|
|
1634
|
+
}
|
|
1621
1635
|
let lookCache = null;
|
|
1622
1636
|
let policyCache = null;
|
|
1623
1637
|
const keepPolicy = (settings) => {
|
|
@@ -1691,7 +1705,9 @@ function createCauthy(given = {}) {
|
|
|
1691
1705
|
"/me/organizations/members/invite",
|
|
1692
1706
|
"/me/organizations/rename",
|
|
1693
1707
|
"/me/organizations/archive",
|
|
1694
|
-
"/me/organizations/delete"
|
|
1708
|
+
"/me/organizations/delete",
|
|
1709
|
+
"/invitation",
|
|
1710
|
+
"/invitation/accept"
|
|
1695
1711
|
].includes(route) || route.startsWith("/sign-in/social/") || route.startsWith("/callback/") || route.startsWith("/me/identities/link/") || route.startsWith("/me/upgrade/social/") || route === "/sign-in/sso" || route === "/sign-in/sso/discover" || route === "/sso/callback";
|
|
1696
1712
|
if (!own) return null;
|
|
1697
1713
|
if (tenant === "") {
|
|
@@ -1713,17 +1729,21 @@ function createCauthy(given = {}) {
|
|
|
1713
1729
|
]);
|
|
1714
1730
|
const list = Array.isArray(providers.data) ? providers.data : [];
|
|
1715
1731
|
const password = keepPolicy(settings);
|
|
1716
|
-
const
|
|
1732
|
+
const passkeys = settings.data?.allow_passkeys !== false;
|
|
1733
|
+
const here = passkeys && place.data?.here === true;
|
|
1717
1734
|
return json({
|
|
1718
|
-
providers: list.map((p) => ({ id: String(p.provider ?? p.id ?? ""), name: String(p.label ?? p.name ?? p.provider ?? "") })).filter((p) => p.id !== ""),
|
|
1735
|
+
providers: list.map((p) => ({ id: String(p.provider ?? p.id ?? ""), name: String(p.label ?? p.name ?? p.provider ?? ""), ...iconOf(p) })).filter((p) => p.id !== ""),
|
|
1736
|
+
// Whether the workspace signs people in with a password at all. A
|
|
1737
|
+
// Cauthy from before the setting says nothing of it: then it does.
|
|
1738
|
+
passwordSignIn: settings.data?.allow_password !== false,
|
|
1719
1739
|
signUp: settings.data?.allow_signup !== false,
|
|
1720
1740
|
// The application's system makes an organization per sign-up: the form asks the company's name.
|
|
1721
1741
|
...settings.data?.signup?.organization?.ask === true ? { organization: { ask: true, required: settings.data.signup.organization.required === true } } : {},
|
|
1722
1742
|
// A sign-in link needs a page of the application to open.
|
|
1723
1743
|
magicLink: settings.data?.allow_magic_link === true && pages.signIn !== void 0,
|
|
1724
|
-
passkey: place.error ? true : here || place.data?.on_cauthy === true,
|
|
1744
|
+
passkey: passkeys && (place.error ? true : here || place.data?.on_cauthy === true),
|
|
1725
1745
|
passkeyHere: here,
|
|
1726
|
-
passkeyOnCauthy: place.error ? true : place.data?.on_cauthy === true,
|
|
1746
|
+
passkeyOnCauthy: passkeys && (place.error ? true : place.data?.on_cauthy === true),
|
|
1727
1747
|
// A company's sign-in, found by the person's work address.
|
|
1728
1748
|
sso: Array.isArray(sso.data) && sso.data.some((c) => c?.discoverable === true),
|
|
1729
1749
|
// The terms a sign-up accepts and the consents it answers, when the workspace asks any.
|
|
@@ -1733,6 +1753,14 @@ function createCauthy(given = {}) {
|
|
|
1733
1753
|
...password ? { password } : {}
|
|
1734
1754
|
});
|
|
1735
1755
|
}
|
|
1756
|
+
if (route === "/invitation" && !post) {
|
|
1757
|
+
const token2 = (url.searchParams.get("token") ?? "").trim();
|
|
1758
|
+
if (token2 === "" || token2.length > 512) return problem(422, "invalid_token", "This invitation is not valid, or it has expired.");
|
|
1759
|
+
const res = await ask(request, "GET", `/v1/auth/invitation?token=${encodeURIComponent(token2)}`);
|
|
1760
|
+
if (res.error) return problem(res.status, res.error.code, res.error.message);
|
|
1761
|
+
const organization = typeof res.data?.organization === "string" && res.data.organization !== "" ? { organization: res.data.organization } : {};
|
|
1762
|
+
return json({ status: "ok", invitation: { email: String(res.data?.email ?? ""), workspace: String(res.data?.workspace ?? ""), ...organization } });
|
|
1763
|
+
}
|
|
1736
1764
|
if (route === "/sign-in/sso" && !post) {
|
|
1737
1765
|
const returnTo = localPath(url.searchParams.get("return_to"), afterSignIn);
|
|
1738
1766
|
const failed2 = (code) => redirect(`${returnTo}${returnTo.includes("?") ? "&" : "?"}auth_error=${encodeURIComponent(code)}`);
|
|
@@ -1962,12 +1990,7 @@ function createCauthy(given = {}) {
|
|
|
1962
1990
|
if (bad) return invalid(bad);
|
|
1963
1991
|
const res = await ask(request, "POST", "/v1/auth/login", { email: String(b.email).trim(), password: b.password });
|
|
1964
1992
|
if (res.error) return problem(res.status, res.error.code, res.error.message);
|
|
1965
|
-
|
|
1966
|
-
const step = { kind: "mfa", token: String(res.data.mfa_token ?? ""), returnTo: afterSignIn };
|
|
1967
|
-
const how = res.data.mfa_method === "email" ? { method: "email" } : {};
|
|
1968
|
-
return json({ status: "mfa_required", ...how }, 200, new Headers({ "set-cookie": writeCookie(stepCookie, await seal(step, await key), attrs(request, STEP_SECONDS)) }));
|
|
1969
|
-
}
|
|
1970
|
-
return signedIn(request, res.data);
|
|
1993
|
+
return loggedIn(request, res.data);
|
|
1971
1994
|
}
|
|
1972
1995
|
if (route === "/sign-in/mfa") {
|
|
1973
1996
|
const bad = checkCode(b.code);
|
|
@@ -2188,13 +2211,13 @@ function createCauthy(given = {}) {
|
|
|
2188
2211
|
if (bad) return invalid(bad);
|
|
2189
2212
|
const role = typeof b.role === "string" ? b.role : "";
|
|
2190
2213
|
if (role === "") return problem(400, "invalid_role", "Choose a role.", "role", mine.headers);
|
|
2191
|
-
const res = await
|
|
2214
|
+
const res = await ask(request, "POST", base, {
|
|
2192
2215
|
email: String(b.email).trim(),
|
|
2193
2216
|
role,
|
|
2194
2217
|
name: typeof b.name === "string" ? b.name.trim() : "",
|
|
2195
2218
|
client_id: clientId,
|
|
2196
2219
|
...typeof b.locale === "string" && b.locale ? { locale: b.locale } : {}
|
|
2197
|
-
});
|
|
2220
|
+
}, pages.acceptInvite, mine.token);
|
|
2198
2221
|
if (res.error) return refused(res, res.error.code === "unknown_role" ? "role" : "email");
|
|
2199
2222
|
return json({ status: "added", member: orgMemberOf(res.data) }, 200, mine.headers);
|
|
2200
2223
|
}
|
|
@@ -2214,7 +2237,7 @@ function createCauthy(given = {}) {
|
|
|
2214
2237
|
return json({ status: "removed", userId: user }, 200, mine.headers);
|
|
2215
2238
|
}
|
|
2216
2239
|
if (route === "/me/organizations/members/invite") {
|
|
2217
|
-
const res = await
|
|
2240
|
+
const res = await ask(request, "POST", `${base}/${user}/invite`, { client_id: clientId, ...typeof b.locale === "string" && b.locale ? { locale: b.locale } : {} }, pages.acceptInvite, mine.token);
|
|
2218
2241
|
if (res.error) return refused(res);
|
|
2219
2242
|
return json({ status: "sent", userId: user }, 200, mine.headers);
|
|
2220
2243
|
}
|
|
@@ -2253,6 +2276,14 @@ function createCauthy(given = {}) {
|
|
|
2253
2276
|
if (res.data?.access_token) return signedIn(request, res.data);
|
|
2254
2277
|
return json({ status: "verified" });
|
|
2255
2278
|
}
|
|
2279
|
+
if (route === "/invitation/accept") {
|
|
2280
|
+
if (!isToken(b.token)) return problem(422, "invalid_token", "This invitation is not valid, or it has expired.");
|
|
2281
|
+
const bad = await newPasswordProblem(request, b.password);
|
|
2282
|
+
if (bad) return invalid(bad);
|
|
2283
|
+
const res = await ask(request, "POST", "/v1/auth/invitation/accept", { token: String(b.token), password: b.password });
|
|
2284
|
+
if (res.error) return problem(res.status, res.error.code, res.error.message, res.error.code === "weak_password" ? "password" : void 0, void 0, res.error.reasons);
|
|
2285
|
+
return loggedIn(request, res.data);
|
|
2286
|
+
}
|
|
2256
2287
|
if (route === "/sign-in/passkey/begin") {
|
|
2257
2288
|
const email = typeof b.email === "string" && checkEmail(b.email) === null ? b.email.trim() : "";
|
|
2258
2289
|
const res = await ask(request, "POST", "/v1/auth/webauthn/login/begin", email !== "" ? { email } : {});
|
|
@@ -2410,6 +2441,18 @@ function createCauthy(given = {}) {
|
|
|
2410
2441
|
options: { issuer, clientId, basePath, afterSignIn, afterSignOut, cookieName }
|
|
2411
2442
|
};
|
|
2412
2443
|
}
|
|
2444
|
+
function iconFor(issuer) {
|
|
2445
|
+
return (p) => {
|
|
2446
|
+
const raw = typeof p?.icon_url === "string" ? p.icon_url.trim() : "";
|
|
2447
|
+
if (raw === "") return {};
|
|
2448
|
+
try {
|
|
2449
|
+
const url = new URL(raw.startsWith("/") && !raw.startsWith("//") ? `${issuer}${raw}` : raw);
|
|
2450
|
+
return url.protocol === "https:" || url.protocol === "http:" ? { iconUrl: url.href } : {};
|
|
2451
|
+
} catch {
|
|
2452
|
+
return {};
|
|
2453
|
+
}
|
|
2454
|
+
};
|
|
2455
|
+
}
|
|
2413
2456
|
function legalOf(raw) {
|
|
2414
2457
|
const documents = Array.isArray(raw?.documents) ? raw.documents : [];
|
|
2415
2458
|
const purposes = Array.isArray(raw?.consent_purposes) ? raw.consent_purposes : [];
|