@orangecheck/me-client 0.42.1 → 0.44.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 +15 -0
- package/dist/server.d.mts +14 -1
- package/dist/server.d.ts +14 -1
- package/dist/server.js +53 -8
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +54 -10
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
package/dist/server.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { verifyOcToken as verifyOcToken$1, checkOcToken as checkOcToken$1, readOcSessionToken, SAFE_METHODS, integratorRevocationCheck, bondMeets, readBondClaim } from '@orangecheck/auth-core';
|
|
1
|
+
import { verifyOcToken as verifyOcToken$1, checkOcToken as checkOcToken$1, readOcSessionToken, SAFE_METHODS, familyRevocationCheck, integratorRevocationCheck, bondMeets, readBondClaim } from '@orangecheck/auth-core';
|
|
2
2
|
export { bondMeets, readBondClaim } from '@orangecheck/auth-core';
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -837,10 +837,18 @@ async function post2(url, tokens, timeoutMs) {
|
|
|
837
837
|
}
|
|
838
838
|
|
|
839
839
|
// src/server.ts
|
|
840
|
+
var VERIFIED = /* @__PURE__ */ new WeakSet();
|
|
841
|
+
function vouch(session) {
|
|
842
|
+
VERIFIED.add(session);
|
|
843
|
+
return session;
|
|
844
|
+
}
|
|
845
|
+
function isFamily(session) {
|
|
846
|
+
const aud = session.aud;
|
|
847
|
+
return aud === void 0 || Array.isArray(aud) && aud.length === 0;
|
|
848
|
+
}
|
|
840
849
|
function lacksHandle(session, requireHandle) {
|
|
841
|
-
if (requireHandle === false) return false;
|
|
842
|
-
const
|
|
843
|
-
if (aud === void 0) return false;
|
|
850
|
+
if (requireHandle === false || isFamily(session)) return false;
|
|
851
|
+
const rh = session.rh;
|
|
844
852
|
return typeof rh !== "string" || rh.length === 0;
|
|
845
853
|
}
|
|
846
854
|
function checkRequireHandle(requireHandle) {
|
|
@@ -868,7 +876,7 @@ async function verifyOcToken(token, options = {}) {
|
|
|
868
876
|
warnNoHandle(session);
|
|
869
877
|
return null;
|
|
870
878
|
}
|
|
871
|
-
return session;
|
|
879
|
+
return vouch(session);
|
|
872
880
|
}
|
|
873
881
|
async function checkOcToken(token, options = {}) {
|
|
874
882
|
if (options === null || typeof options !== "object") {
|
|
@@ -883,13 +891,22 @@ async function checkOcToken(token, options = {}) {
|
|
|
883
891
|
warnNoHandle(checked.session);
|
|
884
892
|
return { status: "invalid", reason: "no_session_handle" };
|
|
885
893
|
}
|
|
886
|
-
return { status: "valid", session: checked.session };
|
|
894
|
+
return { status: "valid", session: vouch(checked.session) };
|
|
887
895
|
}
|
|
888
896
|
var sessionChecks = /* @__PURE__ */ new Map();
|
|
889
897
|
var warnedUnchecked = false;
|
|
890
|
-
function revocationFor(options) {
|
|
898
|
+
function revocationFor(options, session) {
|
|
891
899
|
if (options.revocation === false) return null;
|
|
892
900
|
if (options.revocation) return options.revocation;
|
|
901
|
+
if (isFamily(session)) {
|
|
902
|
+
const token = typeof process !== "undefined" ? process.env?.OC_REVOCATION_FEED_TOKEN?.trim() : void 0;
|
|
903
|
+
if (!token) {
|
|
904
|
+
throw new Error(
|
|
905
|
+
"@orangecheck/me-client: a family session (no aud) is checked against ochk.io's revocation feed, and OC_REVOCATION_FEED_TOKEN is not set. Set it, or pass `revocation: false` to read family sessions by signature alone."
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
return familyRevocationCheck();
|
|
909
|
+
}
|
|
893
910
|
const key = `${options.meOrigin ?? ""} ${options.projectKey ?? ""}`;
|
|
894
911
|
if (!sessionChecks.has(key)) {
|
|
895
912
|
sessionChecks.set(
|
|
@@ -935,7 +952,7 @@ async function checkOcSession(headers, options = {}) {
|
|
|
935
952
|
warnNoHandle(session);
|
|
936
953
|
return { status: "signed_out", reason: "no_session_handle" };
|
|
937
954
|
}
|
|
938
|
-
const check = revocationFor(options);
|
|
955
|
+
const check = revocationFor(options, session);
|
|
939
956
|
if (check) {
|
|
940
957
|
const state = await check.status(session);
|
|
941
958
|
if (state === "revoked") return { status: "signed_out" };
|
|
@@ -943,7 +960,7 @@ async function checkOcSession(headers, options = {}) {
|
|
|
943
960
|
return { status: "unavailable", reason: "revocations_unavailable" };
|
|
944
961
|
}
|
|
945
962
|
}
|
|
946
|
-
return { status: "signed_in", session };
|
|
963
|
+
return { status: "signed_in", session: vouch(session) };
|
|
947
964
|
}
|
|
948
965
|
var unavailable = (checked) => ({
|
|
949
966
|
status: 503,
|
|
@@ -1113,6 +1130,33 @@ async function refusal(session, options, why) {
|
|
|
1113
1130
|
}
|
|
1114
1131
|
return null;
|
|
1115
1132
|
}
|
|
1133
|
+
var SIGN_IN_RULE_OPTIONS = /* @__PURE__ */ new Set([
|
|
1134
|
+
"projectKey",
|
|
1135
|
+
"meOrigin",
|
|
1136
|
+
"requireBond"
|
|
1137
|
+
]);
|
|
1138
|
+
async function checkSignInRule(session, options) {
|
|
1139
|
+
if (options === null || typeof options !== "object") {
|
|
1140
|
+
throw new TypeError("@orangecheck/me-client: options must be an object");
|
|
1141
|
+
}
|
|
1142
|
+
const unknown = Object.keys(options).filter((k) => !SIGN_IN_RULE_OPTIONS.has(k));
|
|
1143
|
+
if (unknown.length > 0) {
|
|
1144
|
+
throw new TypeError(
|
|
1145
|
+
`@orangecheck/me-client: unknown option ${unknown.join(", ")}. It reads only ${[...SIGN_IN_RULE_OPTIONS].join(", ")}.`
|
|
1146
|
+
);
|
|
1147
|
+
}
|
|
1148
|
+
checkOptions(options);
|
|
1149
|
+
if (!options.projectKey && !options.requireBond) {
|
|
1150
|
+
throw new TypeError("@orangecheck/me-client: checkSignInRule needs projectKey or requireBond");
|
|
1151
|
+
}
|
|
1152
|
+
if (session === null || typeof session !== "object" || !VERIFIED.has(session)) {
|
|
1153
|
+
throw new TypeError(
|
|
1154
|
+
"@orangecheck/me-client: checkSignInRule takes the session verifyOcToken, checkOcToken or getOcSession returned, as is, not claims read some other way"
|
|
1155
|
+
);
|
|
1156
|
+
}
|
|
1157
|
+
const refused2 = await refusal(session, options);
|
|
1158
|
+
return refused2 ? { ok: false, status: refused2.status, body: refused2.body } : { ok: true };
|
|
1159
|
+
}
|
|
1116
1160
|
function withOcAuth(handler, options = {}) {
|
|
1117
1161
|
checkOptions(options);
|
|
1118
1162
|
return async (req, res) => {
|
|
@@ -1176,6 +1220,6 @@ function ocAuthHono(options = {}) {
|
|
|
1176
1220
|
};
|
|
1177
1221
|
}
|
|
1178
1222
|
|
|
1179
|
-
export { BACK_ACCOUNT_URL, CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL, MemoryJtiStore, _resetSessionChecksForTests, checkOcSession, checkOcToken, connectClaimLink, connectDelete, connectProvision, getOcSession, identity, ocAuthExpress, ocAuthHono, refreshEnvelopeJwks, revokeToken, spendOnce, verifyActivityAttestation, verifyOcToken, withOcAuth };
|
|
1223
|
+
export { BACK_ACCOUNT_URL, CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL, MemoryJtiStore, _resetSessionChecksForTests, checkOcSession, checkOcToken, checkSignInRule, connectClaimLink, connectDelete, connectProvision, getOcSession, identity, ocAuthExpress, ocAuthHono, refreshEnvelopeJwks, revokeToken, spendOnce, verifyActivityAttestation, verifyOcToken, withOcAuth };
|
|
1180
1224
|
//# sourceMappingURL=server.mjs.map
|
|
1181
1225
|
//# sourceMappingURL=server.mjs.map
|