cauthy-auth 0.28.0 → 0.28.1
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 +1 -1
- package/dist/{cauthy-DGAy45G2.d.ts → cauthy-BAwAJChs.d.ts} +1 -1
- package/dist/{cauthy-XkIbG5gE.d.mts → cauthy-CTVg4kvo.d.mts} +1 -1
- package/dist/client.d.mts +1 -1
- package/dist/client.d.ts +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 +27 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -2
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +2 -2
- package/dist/next.d.ts +2 -2
- package/dist/svelte.d.mts +2 -2
- package/dist/svelte.d.ts +2 -2
- package/dist/{system-DTIeDXDP.d.ts → system-Bn8uckvQ.d.ts} +5 -3
- package/dist/{system-BxMsSIu1.d.mts → system-CVBW_AV8.d.mts} +5 -3
- package/dist/vue.d.mts +2 -2
- package/dist/vue.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ npm install cauthy-auth
|
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
```ts
|
|
15
|
-
// auth.ts — reads CAUTHY_ISSUER, CAUTHY_CLIENT_ID, CAUTHY_SECRET (and CAUTHY_SYSTEM)
|
|
15
|
+
// auth.ts — reads CAUTHY_ISSUER, CAUTHY_CLIENT_ID, CAUTHY_SECRET (and CAUTHY_SYSTEM, CAUTHY_BASE_URL)
|
|
16
16
|
import { createCauthy } from 'cauthy-auth'
|
|
17
17
|
export const auth = createCauthy()
|
|
18
18
|
```
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { J as JsonValue, S as Session, l as SessionStatus, k as SessionOrganization, c as CauthySystem, i as PublicSession, b as CauthyOptions } from './system-
|
|
1
|
+
import { J as JsonValue, S as Session, l as SessionStatus, k as SessionOrganization, c as CauthySystem, i as PublicSession, b as CauthyOptions } from './system-Bn8uckvQ.js';
|
|
2
2
|
import { JWTVerifyGetKey } from 'jose';
|
|
3
3
|
|
|
4
4
|
/** Something that happened in Cauthy, as a subscriber is told. Moments are UTC. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { J as JsonValue, S as Session, l as SessionStatus, k as SessionOrganization, c as CauthySystem, i as PublicSession, b as CauthyOptions } from './system-
|
|
1
|
+
import { J as JsonValue, S as Session, l as SessionStatus, k as SessionOrganization, c as CauthySystem, i as PublicSession, b as CauthyOptions } from './system-CVBW_AV8.mjs';
|
|
2
2
|
import { JWTVerifyGetKey } from 'jose';
|
|
3
3
|
|
|
4
4
|
/** Something that happened in Cauthy, as a subscriber is told. Moments are UTC. */
|
package/dist/client.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CauthyTheme } from './theme.mjs';
|
|
2
|
-
import { i as PublicSession } from './system-
|
|
2
|
+
import { i as PublicSession } from './system-CVBW_AV8.mjs';
|
|
3
3
|
import { A as AuthField, b as PasswordPolicy } from './validate-sEXG82po.mjs';
|
|
4
4
|
export { D as DEFAULT_PASSWORD_POLICY, F as FieldProblem, M as MIN_PASSWORD, P as PasswordClass, a as PasswordLocale, 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 'jose';
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CauthyTheme } from './theme.js';
|
|
2
|
-
import { i as PublicSession } from './system-
|
|
2
|
+
import { i as PublicSession } from './system-Bn8uckvQ.js';
|
|
3
3
|
import { A as AuthField, b as PasswordPolicy } from './validate-sEXG82po.js';
|
|
4
4
|
export { D as DEFAULT_PASSWORD_POLICY, F as FieldProblem, M as MIN_PASSWORD, P as PasswordClass, a as PasswordLocale, 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 'jose';
|
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-CTVg4kvo.mjs';
|
|
3
|
+
import { S as Session } from './system-CVBW_AV8.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-BAwAJChs.js';
|
|
3
|
+
import { S as Session } from './system-Bn8uckvQ.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-CTVg4kvo.mjs';
|
|
3
|
+
import { S as Session } from './system-CVBW_AV8.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-BAwAJChs.js';
|
|
3
|
+
import { S as Session } from './system-Bn8uckvQ.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-CTVg4kvo.mjs';
|
|
3
|
+
import { S as Session } from './system-CVBW_AV8.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-BAwAJChs.js';
|
|
3
|
+
import { S as Session } from './system-Bn8uckvQ.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 { C as CauthyApiError, a as CauthyConfigError, b as CauthyOptions, c as CauthySystem, J as JsonValue, N as NewMember, O as Organization, d as OrganizationMember, P as PermissionOf, e as Permitted, f as Policy, g as PolicyPermission, h as PolicyRole, i as PublicSession, j as PushPolicyOptions, R as RoleOf, S as Session, k as SessionOrganization, l as SessionStatus, m as SessionUser, n as SystemKey, o as SystemOptions, p as can, q as createSystem, r as definePolicy, s as policySource, t as pullPolicy, u 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-CTVg4kvo.mjs';
|
|
2
|
+
export { C as CauthyApiError, a as CauthyConfigError, b as CauthyOptions, c as CauthySystem, J as JsonValue, N as NewMember, O as Organization, d as OrganizationMember, P as PermissionOf, e as Permitted, f as Policy, g as PolicyPermission, h as PolicyRole, i as PublicSession, j as PushPolicyOptions, R as RoleOf, S as Session, k as SessionOrganization, l as SessionStatus, m as SessionUser, n as SystemKey, o as SystemOptions, p as can, q as createSystem, r as definePolicy, s as policySource, t as pullPolicy, u as pushPolicy } from './system-CVBW_AV8.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 { C as CauthyApiError, a as CauthyConfigError, b as CauthyOptions, c as CauthySystem, J as JsonValue, N as NewMember, O as Organization, d as OrganizationMember, P as PermissionOf, e as Permitted, f as Policy, g as PolicyPermission, h as PolicyRole, i as PublicSession, j as PushPolicyOptions, R as RoleOf, S as Session, k as SessionOrganization, l as SessionStatus, m as SessionUser, n as SystemKey, o as SystemOptions, p as can, q as createSystem, r as definePolicy, s as policySource, t as pullPolicy, u 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-BAwAJChs.js';
|
|
2
|
+
export { C as CauthyApiError, a as CauthyConfigError, b as CauthyOptions, c as CauthySystem, J as JsonValue, N as NewMember, O as Organization, d as OrganizationMember, P as PermissionOf, e as Permitted, f as Policy, g as PolicyPermission, h as PolicyRole, i as PublicSession, j as PushPolicyOptions, R as RoleOf, S as Session, k as SessionOrganization, l as SessionStatus, m as SessionUser, n as SystemKey, o as SystemOptions, p as can, q as createSystem, r as definePolicy, s as policySource, t as pullPolicy, u as pushPolicy } from './system-Bn8uckvQ.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
|
@@ -899,6 +899,13 @@ function providerIn(segment) {
|
|
|
899
899
|
function env2(name) {
|
|
900
900
|
return typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
901
901
|
}
|
|
902
|
+
function hostOf(origin) {
|
|
903
|
+
try {
|
|
904
|
+
return new URL(origin).hostname;
|
|
905
|
+
} catch {
|
|
906
|
+
return void 0;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
902
909
|
function b64url(bytes) {
|
|
903
910
|
let s = "";
|
|
904
911
|
for (const b of bytes) s += String.fromCharCode(b);
|
|
@@ -932,6 +939,10 @@ function createCauthy(given = {}) {
|
|
|
932
939
|
if (!/^https?:\/\//.test(issuer)) throw new CauthyConfigError("issuer (CAUTHY_ISSUER) must be Cauthy's address, e.g. https://id.example.com");
|
|
933
940
|
if (clientId === "") throw new CauthyConfigError("clientId (CAUTHY_CLIENT_ID) is required");
|
|
934
941
|
if (secret.length < 32) throw new CauthyConfigError("secret (CAUTHY_SECRET) must be at least 32 characters: it encrypts the session cookie");
|
|
942
|
+
const baseURL = given.baseURL ?? env2("CAUTHY_BASE_URL");
|
|
943
|
+
if (baseURL !== void 0 && baseURL !== "" && !/^https?:\/\/[^/]+\/*$/.test(baseURL)) {
|
|
944
|
+
throw new CauthyConfigError("baseURL (CAUTHY_BASE_URL) must be the application's public origin, e.g. https://app.example.com");
|
|
945
|
+
}
|
|
935
946
|
const basePath = "/" + (given.basePath ?? "/api/auth").replace(/^\/+|\/+$/g, "");
|
|
936
947
|
const afterSignIn = localPath(given.afterSignIn, "/");
|
|
937
948
|
const afterSignOut = localPath(given.afterSignOut, "/");
|
|
@@ -947,7 +958,12 @@ function createCauthy(given = {}) {
|
|
|
947
958
|
verifyEmail: given.pages?.verifyEmail ? localPath(given.pages.verifyEmail, "/") : void 0
|
|
948
959
|
};
|
|
949
960
|
const ownSystem = createSystem({ issuer, clientId, clientSecret, key: given.systemKey, fetch: given.fetch });
|
|
950
|
-
const originOf = (request) =>
|
|
961
|
+
const originOf = (request) => {
|
|
962
|
+
if (baseURL) return withoutTrailingSlashes(baseURL);
|
|
963
|
+
const url = new URL(request.url);
|
|
964
|
+
const proto = request.headers.get("x-forwarded-proto")?.split(",")[0]?.trim().toLowerCase();
|
|
965
|
+
return proto === "https" || proto === "http" ? `${proto}://${url.host}` : url.origin;
|
|
966
|
+
};
|
|
951
967
|
const attrs = (request, maxAge) => ({ secure: originOf(request).startsWith("https://"), maxAge });
|
|
952
968
|
async function token(form) {
|
|
953
969
|
const body2 = new URLSearchParams({ client_id: clientId, ...form });
|
|
@@ -1245,9 +1261,18 @@ function createCauthy(given = {}) {
|
|
|
1245
1261
|
});
|
|
1246
1262
|
const problem = (status2, code, message, field, headers, reasons) => json({ error: { code, message, ...field ? { field } : {}, ...reasons && reasons.length > 0 ? { reasons } : {} } }, status2, headers);
|
|
1247
1263
|
const invalid = (p) => problem(400, p.code, p.message, p.field);
|
|
1264
|
+
let explained = false;
|
|
1248
1265
|
function ownRequest(request) {
|
|
1249
1266
|
const origin = request.headers.get("origin");
|
|
1250
|
-
if (origin !== null)
|
|
1267
|
+
if (origin !== null) {
|
|
1268
|
+
const own = originOf(request);
|
|
1269
|
+
if (origin === own || origin === new URL(request.url).origin) return true;
|
|
1270
|
+
if (!explained && hostOf(origin) === new URL(own).hostname) {
|
|
1271
|
+
explained = true;
|
|
1272
|
+
console.warn(`cauthy-auth: refused a request from ${origin} as cross_site: this application sees itself as ${own}. Behind a proxy? Set CAUTHY_BASE_URL (or baseURL) to the public origin.`);
|
|
1273
|
+
}
|
|
1274
|
+
return false;
|
|
1275
|
+
}
|
|
1251
1276
|
return (request.headers.get("sec-fetch-site") ?? "same-origin") === "same-origin";
|
|
1252
1277
|
}
|
|
1253
1278
|
async function body(request) {
|