@orangecheck/me-client 0.39.0 → 0.40.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 +1 -1
- package/dist/server.d.mts +10 -3
- package/dist/server.d.ts +10 -3
- package/dist/server.js +49 -14
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +51 -13
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
package/dist/server.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getOcSession as getOcSession$1, SAFE_METHODS, integratorRevocationCheck, bondMeets, readBondClaim } from '@orangecheck/auth-core';
|
|
2
|
-
export { bondMeets, readBondClaim
|
|
1
|
+
import { verifyOcToken as verifyOcToken$1, getOcSession as getOcSession$1, SAFE_METHODS, integratorRevocationCheck, bondMeets, readBondClaim } from '@orangecheck/auth-core';
|
|
2
|
+
export { bondMeets, readBondClaim } from '@orangecheck/auth-core';
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -733,6 +733,39 @@ var CONNECT_CONSENT_LABEL = "Also create my orangecheck account";
|
|
|
733
733
|
var CONNECT_CONSENT_BLURB = "It stays with orangecheck until you claim it at ochk.app. Then you can use it on other sites, or delete it.";
|
|
734
734
|
|
|
735
735
|
// src/server.ts
|
|
736
|
+
function lacksHandle(session, requireHandle) {
|
|
737
|
+
if (requireHandle === false) return false;
|
|
738
|
+
const { aud, rh } = session;
|
|
739
|
+
if (aud === void 0) return false;
|
|
740
|
+
return typeof rh !== "string" || rh.length === 0;
|
|
741
|
+
}
|
|
742
|
+
function checkRequireHandle(requireHandle) {
|
|
743
|
+
if (requireHandle !== void 0 && typeof requireHandle !== "boolean") {
|
|
744
|
+
throw new TypeError("@orangecheck/me-client: requireHandle must be true or false");
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
var warnedHandle = false;
|
|
748
|
+
function warnNoHandle(session) {
|
|
749
|
+
if (warnedHandle) return;
|
|
750
|
+
warnedHandle = true;
|
|
751
|
+
console.warn(
|
|
752
|
+
`[@orangecheck/me-client] a sign-in token bound to ${JSON.stringify(session.aud)} carries no revocation handle (rh), so sign out everywhere could not end it, and it was refused (no_session_handle). Tokens from the ochk.app sign-in popup carry one. Pass requireHandle: false only to accept tokens minted some other way.`
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
async function verifyOcToken(token, options = {}) {
|
|
756
|
+
if (options === null || typeof options !== "object") {
|
|
757
|
+
throw new TypeError("@orangecheck/me-client: options must be an object");
|
|
758
|
+
}
|
|
759
|
+
const { requireHandle, ...core } = options;
|
|
760
|
+
checkRequireHandle(requireHandle);
|
|
761
|
+
const session = await verifyOcToken$1(token, core);
|
|
762
|
+
if (!session) return null;
|
|
763
|
+
if (lacksHandle(session, requireHandle)) {
|
|
764
|
+
warnNoHandle(session);
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
return session;
|
|
768
|
+
}
|
|
736
769
|
var sessionChecks = /* @__PURE__ */ new Map();
|
|
737
770
|
var warnedUnchecked = false;
|
|
738
771
|
function revocationFor(options) {
|
|
@@ -761,6 +794,7 @@ function revocationFor(options) {
|
|
|
761
794
|
function _resetSessionChecksForTests() {
|
|
762
795
|
sessionChecks.clear();
|
|
763
796
|
warnedUnchecked = false;
|
|
797
|
+
warnedHandle = false;
|
|
764
798
|
}
|
|
765
799
|
async function getOcSession(headers, options = {}) {
|
|
766
800
|
const checked = await checkOcSession(headers, options);
|
|
@@ -774,6 +808,10 @@ async function checkOcSession(headers, options = {}) {
|
|
|
774
808
|
if (options.audience === void 0) warnIfAudienceMissing(headers);
|
|
775
809
|
return { status: "signed_out" };
|
|
776
810
|
}
|
|
811
|
+
if (lacksHandle(session, options.requireHandle)) {
|
|
812
|
+
warnNoHandle(session);
|
|
813
|
+
return { status: "signed_out", reason: "no_session_handle" };
|
|
814
|
+
}
|
|
777
815
|
const check = revocationFor(options);
|
|
778
816
|
if (check) {
|
|
779
817
|
const state = await check.status(session);
|
|
@@ -785,6 +823,7 @@ async function checkOcSession(headers, options = {}) {
|
|
|
785
823
|
return { status: "signed_in", session };
|
|
786
824
|
}
|
|
787
825
|
var UNAVAILABLE = { status: 503, body: { ok: false, reason: "revocations_unavailable" } };
|
|
826
|
+
var refusedFor = (checked) => checked.status === "signed_out" ? checked.reason : void 0;
|
|
788
827
|
var warnedAudience = false;
|
|
789
828
|
function warnIfAudienceMissing(headers) {
|
|
790
829
|
if (warnedAudience) return;
|
|
@@ -819,6 +858,7 @@ var KNOWN_OPTIONS = /* @__PURE__ */ new Set([
|
|
|
819
858
|
"projectKey",
|
|
820
859
|
"meOrigin",
|
|
821
860
|
"revocation",
|
|
861
|
+
"requireHandle",
|
|
822
862
|
"required",
|
|
823
863
|
"requireBond"
|
|
824
864
|
]);
|
|
@@ -833,6 +873,7 @@ function checkOptions(options) {
|
|
|
833
873
|
`@orangecheck/me-client: unknown option ${unknown.join(", ")}. It reads only ${[...KNOWN_OPTIONS].join(", ")}.`
|
|
834
874
|
);
|
|
835
875
|
}
|
|
876
|
+
checkRequireHandle(options.requireHandle);
|
|
836
877
|
const bond = options.requireBond;
|
|
837
878
|
if (bond === void 0) return;
|
|
838
879
|
if (bond === null || typeof bond !== "object") {
|
|
@@ -915,10 +956,9 @@ async function bondNeed(options) {
|
|
|
915
956
|
if (options.projectKey) return projectRequirement(options);
|
|
916
957
|
return null;
|
|
917
958
|
}
|
|
918
|
-
async function refusal(session, options) {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
}
|
|
959
|
+
async function refusal(session, options, why) {
|
|
960
|
+
const unauthenticated = { status: 401, body: { ok: false, reason: why ?? "unauthenticated" } };
|
|
961
|
+
if (!session && options.required) return unauthenticated;
|
|
922
962
|
if (!session && !options.requireBond) return null;
|
|
923
963
|
const need = await bondNeed(options);
|
|
924
964
|
if (need === UNKNOWN_PROJECT) {
|
|
@@ -927,9 +967,7 @@ async function refusal(session, options) {
|
|
|
927
967
|
if (need === void 0) {
|
|
928
968
|
return { status: 503, body: { ok: false, reason: "bond_policy_unavailable" } };
|
|
929
969
|
}
|
|
930
|
-
if (!session)
|
|
931
|
-
return need ? { status: 401, body: { ok: false, reason: "unauthenticated" } } : null;
|
|
932
|
-
}
|
|
970
|
+
if (!session) return need ? unauthenticated : null;
|
|
933
971
|
if (need && !bondMeets(session, need)) {
|
|
934
972
|
const have = readBondClaim(session);
|
|
935
973
|
return {
|
|
@@ -964,7 +1002,7 @@ function withOcAuth(handler, options = {}) {
|
|
|
964
1002
|
const session = checked.status === "signed_in" ? checked.session : null;
|
|
965
1003
|
const withSession = req;
|
|
966
1004
|
withSession.ocSession = session;
|
|
967
|
-
const refused2 = checked.status === "unavailable" ? UNAVAILABLE : await refusal(session, options);
|
|
1005
|
+
const refused2 = checked.status === "unavailable" ? UNAVAILABLE : await refusal(session, options, refusedFor(checked));
|
|
968
1006
|
if (refused2) return res.status(refused2.status).json(refused2.body);
|
|
969
1007
|
return handler(withSession, res);
|
|
970
1008
|
};
|
|
@@ -984,7 +1022,7 @@ function ocAuthExpress(options = {}) {
|
|
|
984
1022
|
);
|
|
985
1023
|
const session = checked.status === "signed_in" ? checked.session : null;
|
|
986
1024
|
req.ocSession = session;
|
|
987
|
-
const refused2 = checked.status === "unavailable" ? UNAVAILABLE : await refusal(session, options);
|
|
1025
|
+
const refused2 = checked.status === "unavailable" ? UNAVAILABLE : await refusal(session, options, refusedFor(checked));
|
|
988
1026
|
if (refused2) {
|
|
989
1027
|
res.status(refused2.status).json(refused2.body);
|
|
990
1028
|
return;
|
|
@@ -1006,12 +1044,12 @@ function ocAuthHono(options = {}) {
|
|
|
1006
1044
|
});
|
|
1007
1045
|
const session = checked.status === "signed_in" ? checked.session : null;
|
|
1008
1046
|
c.set("ocSession", session);
|
|
1009
|
-
const refused2 = checked.status === "unavailable" ? UNAVAILABLE : await refusal(session, options);
|
|
1047
|
+
const refused2 = checked.status === "unavailable" ? UNAVAILABLE : await refusal(session, options, refusedFor(checked));
|
|
1010
1048
|
if (refused2) return c.json(refused2.body, refused2.status);
|
|
1011
1049
|
await next();
|
|
1012
1050
|
};
|
|
1013
1051
|
}
|
|
1014
1052
|
|
|
1015
|
-
export { BACK_ACCOUNT_URL, CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL, _resetSessionChecksForTests, checkOcSession, connectClaimLink, connectDelete, connectProvision, getOcSession, identity, ocAuthExpress, ocAuthHono, refreshEnvelopeJwks, verifyActivityAttestation, withOcAuth };
|
|
1053
|
+
export { BACK_ACCOUNT_URL, CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL, _resetSessionChecksForTests, checkOcSession, connectClaimLink, connectDelete, connectProvision, getOcSession, identity, ocAuthExpress, ocAuthHono, refreshEnvelopeJwks, verifyActivityAttestation, verifyOcToken, withOcAuth };
|
|
1016
1054
|
//# sourceMappingURL=server.mjs.map
|
|
1017
1055
|
//# sourceMappingURL=server.mjs.map
|