@cauthyhq/node 1.0.0 → 1.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/CHANGELOG.md +43 -0
- package/README.md +4 -0
- package/dist/{cauthy-ClP5orP4.d.mts → cauthy-Bn-i7cKD.d.mts} +24 -1
- package/dist/{cauthy-B6Sm3T8M.d.ts → cauthy-Wy-YDGrM.d.ts} +24 -1
- package/dist/express.d.mts +1 -1
- package/dist/express.d.ts +1 -1
- package/dist/fastify.d.mts +1 -1
- package/dist/fastify.d.ts +1 -1
- package/dist/hono.d.mts +1 -1
- package/dist/hono.d.ts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -7
- package/dist/index.mjs.map +1 -1
- package/dist/mcp.js.map +1 -1
- package/dist/mcp.mjs.map +1 -1
- package/dist/next.d.mts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/testing.d.mts +13 -1
- package/dist/testing.d.ts +13 -1
- package/dist/testing.js +93 -5
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +91 -4
- package/dist/testing.mjs.map +1 -1
- package/package.json +8 -3
package/dist/index.mjs
CHANGED
|
@@ -1745,6 +1745,7 @@ function createTokenVerifier(options = {}) {
|
|
|
1745
1745
|
if (claims.roles !== void 0 && claims.roles !== null && !(Array.isArray(claims.roles) && claims.roles.every((r) => typeof r === "string"))) bad("roles");
|
|
1746
1746
|
if (claims.email !== void 0 && typeof claims.email !== "string") bad("email");
|
|
1747
1747
|
for (const name of ["email_verified", "anon"]) if (claims[name] !== void 0 && typeof claims[name] !== "boolean") bad(name);
|
|
1748
|
+
for (const name of ["token_use", "azp"]) if (claims[name] !== void 0 && typeof claims[name] !== "string") bad(name);
|
|
1748
1749
|
if (!issuers.includes(claims.iss)) throw new CauthyTokenError("wrong_issuer");
|
|
1749
1750
|
if (!(Array.isArray(aud) ? aud.includes(audience) : aud === audience)) throw new CauthyTokenError("wrong_audience");
|
|
1750
1751
|
const now = (options.now ?? /* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
@@ -1753,7 +1754,9 @@ function createTokenVerifier(options = {}) {
|
|
|
1753
1754
|
if (now < claims.iat - leeway) throw new CauthyTokenError("issued_in_future");
|
|
1754
1755
|
if (claims.tid !== tenant) throw new CauthyTokenError("wrong_tenant");
|
|
1755
1756
|
if ("sys" in claims && !options.allowSystem) throw new CauthyTokenError("system_token");
|
|
1757
|
+
if ("token_use" in claims && !options.allowClientTokens) throw new CauthyTokenError("client_token");
|
|
1756
1758
|
if (claims.anon === true && !options.allowAnonymous) throw new CauthyTokenError("anonymous_token");
|
|
1759
|
+
if (options.clientId && typeof claims.azp === "string" && claims.azp !== "" && claims.azp !== options.clientId) throw new CauthyTokenError("wrong_client");
|
|
1757
1760
|
return {
|
|
1758
1761
|
userId: claims.sub,
|
|
1759
1762
|
tenantId: claims.tid,
|
|
@@ -1762,6 +1765,8 @@ function createTokenVerifier(options = {}) {
|
|
|
1762
1765
|
roles: Array.isArray(claims.roles) ? claims.roles : [],
|
|
1763
1766
|
...typeof claims.sys === "string" && claims.sys !== "" ? { system: claims.sys } : {},
|
|
1764
1767
|
...claims.anon === true ? { anonymous: true } : {},
|
|
1768
|
+
...typeof claims.azp === "string" && claims.azp !== "" ? { authorizedParty: claims.azp } : {},
|
|
1769
|
+
...typeof claims.client_id === "string" && claims.client_id !== "" ? { clientId: claims.client_id } : {},
|
|
1765
1770
|
expiresAt: new Date(claims.exp * 1e3).toISOString(),
|
|
1766
1771
|
token
|
|
1767
1772
|
};
|
|
@@ -3261,13 +3266,19 @@ function createCauthy(given = {}) {
|
|
|
3261
3266
|
return { response: redirect(to) };
|
|
3262
3267
|
}
|
|
3263
3268
|
const replay = given.webhookReplay ?? memoryReplayStore();
|
|
3264
|
-
const tokenVerifier = (o = {}) =>
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3269
|
+
const tokenVerifier = (o = {}) => {
|
|
3270
|
+
if (contract && o.clientId !== void 0 && o.clientId !== contract.clientId) {
|
|
3271
|
+
throw new CauthyConfigError(`clientId is the contract's (${contract.clientId}): remove it from the call`);
|
|
3272
|
+
}
|
|
3273
|
+
return createTokenVerifier({
|
|
3274
|
+
issuer,
|
|
3275
|
+
tenantId: contract?.tenantId ?? given.tenantId,
|
|
3276
|
+
audience: given.audience,
|
|
3277
|
+
fetch: given.fetch,
|
|
3278
|
+
...contract ? { clientId: contract.clientId } : {},
|
|
3279
|
+
...o
|
|
3280
|
+
});
|
|
3281
|
+
};
|
|
3271
3282
|
const webhook = (request, o = {}) => verifyWebhook(request, { issuer, url: o.url ?? `${originOf(request)}${new URL(request.url).pathname}`, jwks: o.jwks, now: o.now, replay });
|
|
3272
3283
|
const pact = contract && ownKeys ? {
|
|
3273
3284
|
contract,
|