@orangecheck/me-client 0.38.3 → 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 +30 -1
- package/dist/connect-consent.d.mts +4 -0
- package/dist/connect-consent.d.ts +4 -0
- package/dist/connect-consent.js +10 -0
- package/dist/connect-consent.js.map +1 -0
- package/dist/connect-consent.mjs +7 -0
- package/dist/connect-consent.mjs.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +47 -3
- package/dist/server.d.ts +47 -3
- package/dist/server.js +222 -18
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +219 -17
- package/dist/server.mjs.map +1 -1
- package/package.json +6 -1
package/dist/server.d.mts
CHANGED
|
@@ -1,8 +1,51 @@
|
|
|
1
1
|
import { SessionPayload, VerifyOcOptions, RevocationCheck, SessionRequestHeaders } from '@orangecheck/auth-core';
|
|
2
|
-
export { BondClaim, SessionPayload, VerifyOcOptions, bondMeets, readBondClaim
|
|
2
|
+
export { BondClaim, SessionPayload, VerifyOcOptions, bondMeets, readBondClaim } from '@orangecheck/auth-core';
|
|
3
3
|
export { A as ActivityAttestation, a as ActivityAttestationBundle, b as ActivityVerifyCheck, c as ActivityVerifyResult, V as VerifyActivityOptions, i as identity, r as refreshEnvelopeJwks, v as verifyActivityAttestation } from './identity-DfxCvxuH.mjs';
|
|
4
|
+
export { CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL } from './connect-consent.mjs';
|
|
4
5
|
|
|
5
|
-
interface
|
|
6
|
+
interface ConnectOptions {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
}
|
|
11
|
+
interface ConnectProvisionOptions extends ConnectOptions {
|
|
12
|
+
consent?: true;
|
|
13
|
+
email?: string;
|
|
14
|
+
emailVerified?: boolean;
|
|
15
|
+
}
|
|
16
|
+
type ConnectProvisionRefusal = 'account_deleted' | 'daily_limit' | 'rate_limited' | 'invalid_api_key' | 'app_suspended' | 'bad_request' | 'unavailable';
|
|
17
|
+
type ConnectDeleteRefusal = 'unknown_user' | 'holds_earnings' | 'not_deletable' | 'rate_limited' | 'invalid_api_key' | 'bad_request' | 'unavailable';
|
|
18
|
+
type ConnectClaimLinkRefusal = 'unknown_user' | 'already_claimed' | 'rate_limited' | 'invalid_api_key' | 'app_suspended' | 'bad_request' | 'unavailable';
|
|
19
|
+
interface ConnectRefused<R extends string> {
|
|
20
|
+
ok: false;
|
|
21
|
+
reason: R;
|
|
22
|
+
status: number;
|
|
23
|
+
}
|
|
24
|
+
type ConnectProvisionResult = {
|
|
25
|
+
ok: true;
|
|
26
|
+
did_oc: string;
|
|
27
|
+
is_new: boolean;
|
|
28
|
+
} | ConnectRefused<ConnectProvisionRefusal>;
|
|
29
|
+
type ConnectDeleteResult = {
|
|
30
|
+
ok: true;
|
|
31
|
+
result: 'deleted' | 'detached' | 'already_deleted';
|
|
32
|
+
} | ConnectRefused<ConnectDeleteRefusal>;
|
|
33
|
+
type ConnectClaimLinkResult = {
|
|
34
|
+
ok: true;
|
|
35
|
+
url: string;
|
|
36
|
+
expires_at: string;
|
|
37
|
+
} | ConnectRefused<ConnectClaimLinkRefusal>;
|
|
38
|
+
declare function connectProvision(options: ConnectProvisionOptions): Promise<ConnectProvisionResult>;
|
|
39
|
+
declare function connectClaimLink(options: ConnectOptions): Promise<ConnectClaimLinkResult>;
|
|
40
|
+
declare function connectDelete(options: ConnectOptions): Promise<ConnectDeleteResult>;
|
|
41
|
+
|
|
42
|
+
type OcSessionRefusal = 'no_session_handle';
|
|
43
|
+
interface VerifyOcTokenOptions extends VerifyOcOptions {
|
|
44
|
+
requireHandle?: boolean;
|
|
45
|
+
}
|
|
46
|
+
declare function verifyOcToken(token: string, options?: VerifyOcTokenOptions): Promise<SessionPayload | null>;
|
|
47
|
+
|
|
48
|
+
interface OcSessionOptions extends VerifyOcTokenOptions {
|
|
6
49
|
method?: string;
|
|
7
50
|
projectKey?: string;
|
|
8
51
|
meOrigin?: string;
|
|
@@ -15,6 +58,7 @@ type OcSessionCheck = {
|
|
|
15
58
|
session: SessionPayload;
|
|
16
59
|
} | {
|
|
17
60
|
status: 'signed_out';
|
|
61
|
+
reason?: OcSessionRefusal;
|
|
18
62
|
} | {
|
|
19
63
|
status: 'unavailable';
|
|
20
64
|
};
|
|
@@ -89,4 +133,4 @@ interface HonoContextLike {
|
|
|
89
133
|
type HonoNextLike = () => Promise<void>;
|
|
90
134
|
declare function ocAuthHono(options?: WithOcAuthOptions): (c: HonoContextLike, next: HonoNextLike) => Promise<unknown>;
|
|
91
135
|
|
|
92
|
-
export { BACK_ACCOUNT_URL, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, getOcSession, ocAuthExpress, ocAuthHono, withOcAuth };
|
|
136
|
+
export { BACK_ACCOUNT_URL, type ConnectClaimLinkRefusal, type ConnectClaimLinkResult, type ConnectDeleteRefusal, type ConnectDeleteResult, type ConnectOptions, type ConnectProvisionOptions, type ConnectProvisionRefusal, type ConnectProvisionResult, type ConnectRefused, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type OcSessionRefusal, type VerifyOcTokenOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, connectClaimLink, connectDelete, connectProvision, getOcSession, ocAuthExpress, ocAuthHono, verifyOcToken, withOcAuth };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,8 +1,51 @@
|
|
|
1
1
|
import { SessionPayload, VerifyOcOptions, RevocationCheck, SessionRequestHeaders } from '@orangecheck/auth-core';
|
|
2
|
-
export { BondClaim, SessionPayload, VerifyOcOptions, bondMeets, readBondClaim
|
|
2
|
+
export { BondClaim, SessionPayload, VerifyOcOptions, bondMeets, readBondClaim } from '@orangecheck/auth-core';
|
|
3
3
|
export { A as ActivityAttestation, a as ActivityAttestationBundle, b as ActivityVerifyCheck, c as ActivityVerifyResult, V as VerifyActivityOptions, i as identity, r as refreshEnvelopeJwks, v as verifyActivityAttestation } from './identity-DfxCvxuH.js';
|
|
4
|
+
export { CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL } from './connect-consent.js';
|
|
4
5
|
|
|
5
|
-
interface
|
|
6
|
+
interface ConnectOptions {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
}
|
|
11
|
+
interface ConnectProvisionOptions extends ConnectOptions {
|
|
12
|
+
consent?: true;
|
|
13
|
+
email?: string;
|
|
14
|
+
emailVerified?: boolean;
|
|
15
|
+
}
|
|
16
|
+
type ConnectProvisionRefusal = 'account_deleted' | 'daily_limit' | 'rate_limited' | 'invalid_api_key' | 'app_suspended' | 'bad_request' | 'unavailable';
|
|
17
|
+
type ConnectDeleteRefusal = 'unknown_user' | 'holds_earnings' | 'not_deletable' | 'rate_limited' | 'invalid_api_key' | 'bad_request' | 'unavailable';
|
|
18
|
+
type ConnectClaimLinkRefusal = 'unknown_user' | 'already_claimed' | 'rate_limited' | 'invalid_api_key' | 'app_suspended' | 'bad_request' | 'unavailable';
|
|
19
|
+
interface ConnectRefused<R extends string> {
|
|
20
|
+
ok: false;
|
|
21
|
+
reason: R;
|
|
22
|
+
status: number;
|
|
23
|
+
}
|
|
24
|
+
type ConnectProvisionResult = {
|
|
25
|
+
ok: true;
|
|
26
|
+
did_oc: string;
|
|
27
|
+
is_new: boolean;
|
|
28
|
+
} | ConnectRefused<ConnectProvisionRefusal>;
|
|
29
|
+
type ConnectDeleteResult = {
|
|
30
|
+
ok: true;
|
|
31
|
+
result: 'deleted' | 'detached' | 'already_deleted';
|
|
32
|
+
} | ConnectRefused<ConnectDeleteRefusal>;
|
|
33
|
+
type ConnectClaimLinkResult = {
|
|
34
|
+
ok: true;
|
|
35
|
+
url: string;
|
|
36
|
+
expires_at: string;
|
|
37
|
+
} | ConnectRefused<ConnectClaimLinkRefusal>;
|
|
38
|
+
declare function connectProvision(options: ConnectProvisionOptions): Promise<ConnectProvisionResult>;
|
|
39
|
+
declare function connectClaimLink(options: ConnectOptions): Promise<ConnectClaimLinkResult>;
|
|
40
|
+
declare function connectDelete(options: ConnectOptions): Promise<ConnectDeleteResult>;
|
|
41
|
+
|
|
42
|
+
type OcSessionRefusal = 'no_session_handle';
|
|
43
|
+
interface VerifyOcTokenOptions extends VerifyOcOptions {
|
|
44
|
+
requireHandle?: boolean;
|
|
45
|
+
}
|
|
46
|
+
declare function verifyOcToken(token: string, options?: VerifyOcTokenOptions): Promise<SessionPayload | null>;
|
|
47
|
+
|
|
48
|
+
interface OcSessionOptions extends VerifyOcTokenOptions {
|
|
6
49
|
method?: string;
|
|
7
50
|
projectKey?: string;
|
|
8
51
|
meOrigin?: string;
|
|
@@ -15,6 +58,7 @@ type OcSessionCheck = {
|
|
|
15
58
|
session: SessionPayload;
|
|
16
59
|
} | {
|
|
17
60
|
status: 'signed_out';
|
|
61
|
+
reason?: OcSessionRefusal;
|
|
18
62
|
} | {
|
|
19
63
|
status: 'unavailable';
|
|
20
64
|
};
|
|
@@ -89,4 +133,4 @@ interface HonoContextLike {
|
|
|
89
133
|
type HonoNextLike = () => Promise<void>;
|
|
90
134
|
declare function ocAuthHono(options?: WithOcAuthOptions): (c: HonoContextLike, next: HonoNextLike) => Promise<unknown>;
|
|
91
135
|
|
|
92
|
-
export { BACK_ACCOUNT_URL, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, getOcSession, ocAuthExpress, ocAuthHono, withOcAuth };
|
|
136
|
+
export { BACK_ACCOUNT_URL, type ConnectClaimLinkRefusal, type ConnectClaimLinkResult, type ConnectDeleteRefusal, type ConnectDeleteResult, type ConnectOptions, type ConnectProvisionOptions, type ConnectProvisionRefusal, type ConnectProvisionResult, type ConnectRefused, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type OcSessionRefusal, type VerifyOcTokenOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, connectClaimLink, connectDelete, connectProvision, getOcSession, ocAuthExpress, ocAuthHono, verifyOcToken, withOcAuth };
|
package/dist/server.js
CHANGED
|
@@ -569,7 +569,204 @@ var identity = {
|
|
|
569
569
|
refreshEnvelopeJwks
|
|
570
570
|
};
|
|
571
571
|
|
|
572
|
+
// src/connect.ts
|
|
573
|
+
var ORIGIN = "https://ochk.io";
|
|
574
|
+
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
575
|
+
var MAX_TIMEOUT_MS = 3e4;
|
|
576
|
+
var DID_OC = /^did:oc:[0-9a-f]{32}$/;
|
|
577
|
+
var BASE_KEYS = ["apiKey", "userId", "timeoutMs"];
|
|
578
|
+
var PROVISION_KEYS = /* @__PURE__ */ new Set([...BASE_KEYS, "consent", "email", "emailVerified"]);
|
|
579
|
+
var USER_KEYS = new Set(BASE_KEYS);
|
|
580
|
+
var PROVISION_REASONS = /* @__PURE__ */ new Set([
|
|
581
|
+
"account_deleted",
|
|
582
|
+
"daily_limit",
|
|
583
|
+
"rate_limited",
|
|
584
|
+
"invalid_api_key",
|
|
585
|
+
"app_suspended",
|
|
586
|
+
"bad_request"
|
|
587
|
+
]);
|
|
588
|
+
var DELETE_REASONS = /* @__PURE__ */ new Set([
|
|
589
|
+
"unknown_user",
|
|
590
|
+
"holds_earnings",
|
|
591
|
+
"not_deletable",
|
|
592
|
+
"rate_limited",
|
|
593
|
+
"invalid_api_key",
|
|
594
|
+
"bad_request"
|
|
595
|
+
]);
|
|
596
|
+
var CLAIM_LINK_REASONS = /* @__PURE__ */ new Set([
|
|
597
|
+
"unknown_user",
|
|
598
|
+
"already_claimed",
|
|
599
|
+
"rate_limited",
|
|
600
|
+
"invalid_api_key",
|
|
601
|
+
"app_suspended",
|
|
602
|
+
"bad_request"
|
|
603
|
+
]);
|
|
604
|
+
var DELETE_RESULTS = /* @__PURE__ */ new Set(["deleted", "detached", "already_deleted"]);
|
|
605
|
+
function fail(message) {
|
|
606
|
+
throw new TypeError(`@orangecheck/me-client: ${message}`);
|
|
607
|
+
}
|
|
608
|
+
function checkCall(name, options, known) {
|
|
609
|
+
if (typeof document !== "undefined") {
|
|
610
|
+
fail(`${name} runs on your server only: in a browser your API key would be exposed`);
|
|
611
|
+
}
|
|
612
|
+
if (options === null || typeof options !== "object") fail(`${name}: options must be an object`);
|
|
613
|
+
const unknown = Object.keys(options).filter((k) => !known.has(k));
|
|
614
|
+
if (unknown.length > 0) {
|
|
615
|
+
const only = [...known].join(", ");
|
|
616
|
+
fail(`${name}: unknown option ${unknown.join(", ")}. It reads only ${only}.`);
|
|
617
|
+
}
|
|
618
|
+
const o = Object.assign(/* @__PURE__ */ Object.create(null), options);
|
|
619
|
+
if (typeof o.apiKey !== "string" || o.apiKey.trim() === "") {
|
|
620
|
+
fail(`${name}: apiKey is required (your Connect API key)`);
|
|
621
|
+
}
|
|
622
|
+
const id = o.userId;
|
|
623
|
+
if (typeof id !== "string" || id.length < 1 || id.length > 256) {
|
|
624
|
+
fail(`${name}: userId must be your user's id, 1 to 256 characters`);
|
|
625
|
+
}
|
|
626
|
+
const t = o.timeoutMs;
|
|
627
|
+
if (t !== void 0 && !(typeof t === "number" && t > 0 && t <= MAX_TIMEOUT_MS)) {
|
|
628
|
+
fail(`${name}: timeoutMs must be above 0 and at most ${MAX_TIMEOUT_MS}`);
|
|
629
|
+
}
|
|
630
|
+
return o;
|
|
631
|
+
}
|
|
632
|
+
async function post(path, apiKey, body, timeoutMs) {
|
|
633
|
+
const controller = new AbortController();
|
|
634
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
635
|
+
try {
|
|
636
|
+
const res = await fetch(`${ORIGIN}${path}`, {
|
|
637
|
+
method: "POST",
|
|
638
|
+
// These endpoints never redirect, so a redirect is an error: the key and
|
|
639
|
+
// the body go to ochk.io and nowhere else.
|
|
640
|
+
redirect: "error",
|
|
641
|
+
headers: {
|
|
642
|
+
"content-type": "application/json",
|
|
643
|
+
authorization: `Bearer ${apiKey}`
|
|
644
|
+
},
|
|
645
|
+
body: JSON.stringify(body),
|
|
646
|
+
signal: controller.signal
|
|
647
|
+
});
|
|
648
|
+
let parsed = null;
|
|
649
|
+
try {
|
|
650
|
+
parsed = await res.json();
|
|
651
|
+
} catch {
|
|
652
|
+
parsed = null;
|
|
653
|
+
}
|
|
654
|
+
const ok = parsed !== null && typeof parsed === "object" && !Array.isArray(parsed);
|
|
655
|
+
return { status: res.status, body: ok ? parsed : null };
|
|
656
|
+
} catch {
|
|
657
|
+
return { status: 0, body: null };
|
|
658
|
+
} finally {
|
|
659
|
+
clearTimeout(timer);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
function refused(answer, known) {
|
|
663
|
+
const raw = answer.body?.reason;
|
|
664
|
+
const said = raw === "missing_api_key" ? "invalid_api_key" : raw;
|
|
665
|
+
const reason = typeof said === "string" && known.has(said) ? said : "unavailable";
|
|
666
|
+
return { ok: false, reason, status: answer.status };
|
|
667
|
+
}
|
|
668
|
+
function connectProvision(options) {
|
|
669
|
+
const o = checkCall("connectProvision", options, PROVISION_KEYS);
|
|
670
|
+
if (o.consent !== void 0 && o.consent !== true) {
|
|
671
|
+
fail(
|
|
672
|
+
"connectProvision: consent must be true or left out. An unticked box means no call at all; a call without consent makes an account nobody asked for"
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
const { email, emailVerified } = o;
|
|
676
|
+
if (email !== void 0 && (typeof email !== "string" || email === "")) {
|
|
677
|
+
fail("connectProvision: email must be a non-empty string");
|
|
678
|
+
}
|
|
679
|
+
if (emailVerified !== void 0 && typeof emailVerified !== "boolean") {
|
|
680
|
+
fail("connectProvision: emailVerified must be a boolean");
|
|
681
|
+
}
|
|
682
|
+
if (emailVerified !== void 0 && email === void 0) {
|
|
683
|
+
fail("connectProvision: emailVerified describes email, so pass email too");
|
|
684
|
+
}
|
|
685
|
+
const body = { user_id: o.userId };
|
|
686
|
+
if (o.consent === true) body.consent = true;
|
|
687
|
+
if (email !== void 0) body.email = email;
|
|
688
|
+
if (emailVerified !== void 0) body.email_verified = emailVerified;
|
|
689
|
+
return call("/api/connect/provision", o, body).then(
|
|
690
|
+
(answer) => {
|
|
691
|
+
const b = answer.body;
|
|
692
|
+
if (answer.status !== 200) return refused(answer, PROVISION_REASONS);
|
|
693
|
+
const good = b?.ok === true && typeof b.did_oc === "string" && DID_OC.test(b.did_oc) && typeof b.is_new === "boolean";
|
|
694
|
+
return good ? { ok: true, did_oc: b.did_oc, is_new: b.is_new } : { ok: false, reason: "unavailable", status: 200 };
|
|
695
|
+
}
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
function connectClaimLink(options) {
|
|
699
|
+
const o = checkCall("connectClaimLink", options, USER_KEYS);
|
|
700
|
+
return call("/api/connect/claim-link", o, { user_id: o.userId }).then(
|
|
701
|
+
(answer) => {
|
|
702
|
+
const b = answer.body;
|
|
703
|
+
if (answer.status !== 200) return refused(answer, CLAIM_LINK_REASONS);
|
|
704
|
+
const good = b?.ok === true && isClaimUrl(b.url) && typeof b.expires_at === "string" && b.expires_at !== "";
|
|
705
|
+
return good ? { ok: true, url: b.url, expires_at: b.expires_at } : { ok: false, reason: "unavailable", status: 200 };
|
|
706
|
+
}
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
function connectDelete(options) {
|
|
710
|
+
const o = checkCall("connectDelete", options, USER_KEYS);
|
|
711
|
+
return call("/api/connect/delete", o, { user_id: o.userId }).then(
|
|
712
|
+
(answer) => {
|
|
713
|
+
const b = answer.body;
|
|
714
|
+
if (answer.status !== 200) return refused(answer, DELETE_REASONS);
|
|
715
|
+
return b?.ok === true && typeof b.result === "string" && DELETE_RESULTS.has(b.result) ? { ok: true, result: b.result } : { ok: false, reason: "unavailable", status: 200 };
|
|
716
|
+
}
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
function call(path, o, body) {
|
|
720
|
+
return post(path, o.apiKey, body, o.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
721
|
+
}
|
|
722
|
+
function isClaimUrl(v) {
|
|
723
|
+
if (typeof v !== "string") return false;
|
|
724
|
+
try {
|
|
725
|
+
const url = new URL(v);
|
|
726
|
+
return url.protocol === "https:" && url.hostname === "ochk.app" && url.port === "" && url.username === "" && url.password === "";
|
|
727
|
+
} catch {
|
|
728
|
+
return false;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// src/connect-consent.ts
|
|
733
|
+
var CONNECT_CONSENT_LABEL = "Also create my orangecheck account";
|
|
734
|
+
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.";
|
|
735
|
+
|
|
572
736
|
// src/server.ts
|
|
737
|
+
function lacksHandle(session, requireHandle) {
|
|
738
|
+
if (requireHandle === false) return false;
|
|
739
|
+
const { aud, rh } = session;
|
|
740
|
+
if (aud === void 0) return false;
|
|
741
|
+
return typeof rh !== "string" || rh.length === 0;
|
|
742
|
+
}
|
|
743
|
+
function checkRequireHandle(requireHandle) {
|
|
744
|
+
if (requireHandle !== void 0 && typeof requireHandle !== "boolean") {
|
|
745
|
+
throw new TypeError("@orangecheck/me-client: requireHandle must be true or false");
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
var warnedHandle = false;
|
|
749
|
+
function warnNoHandle(session) {
|
|
750
|
+
if (warnedHandle) return;
|
|
751
|
+
warnedHandle = true;
|
|
752
|
+
console.warn(
|
|
753
|
+
`[@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.`
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
async function verifyOcToken(token, options = {}) {
|
|
757
|
+
if (options === null || typeof options !== "object") {
|
|
758
|
+
throw new TypeError("@orangecheck/me-client: options must be an object");
|
|
759
|
+
}
|
|
760
|
+
const { requireHandle, ...core } = options;
|
|
761
|
+
checkRequireHandle(requireHandle);
|
|
762
|
+
const session = await authCore.verifyOcToken(token, core);
|
|
763
|
+
if (!session) return null;
|
|
764
|
+
if (lacksHandle(session, requireHandle)) {
|
|
765
|
+
warnNoHandle(session);
|
|
766
|
+
return null;
|
|
767
|
+
}
|
|
768
|
+
return session;
|
|
769
|
+
}
|
|
573
770
|
var sessionChecks = /* @__PURE__ */ new Map();
|
|
574
771
|
var warnedUnchecked = false;
|
|
575
772
|
function revocationFor(options) {
|
|
@@ -598,6 +795,7 @@ function revocationFor(options) {
|
|
|
598
795
|
function _resetSessionChecksForTests() {
|
|
599
796
|
sessionChecks.clear();
|
|
600
797
|
warnedUnchecked = false;
|
|
798
|
+
warnedHandle = false;
|
|
601
799
|
}
|
|
602
800
|
async function getOcSession(headers, options = {}) {
|
|
603
801
|
const checked = await checkOcSession(headers, options);
|
|
@@ -611,6 +809,10 @@ async function checkOcSession(headers, options = {}) {
|
|
|
611
809
|
if (options.audience === void 0) warnIfAudienceMissing(headers);
|
|
612
810
|
return { status: "signed_out" };
|
|
613
811
|
}
|
|
812
|
+
if (lacksHandle(session, options.requireHandle)) {
|
|
813
|
+
warnNoHandle(session);
|
|
814
|
+
return { status: "signed_out", reason: "no_session_handle" };
|
|
815
|
+
}
|
|
614
816
|
const check = revocationFor(options);
|
|
615
817
|
if (check) {
|
|
616
818
|
const state = await check.status(session);
|
|
@@ -622,6 +824,7 @@ async function checkOcSession(headers, options = {}) {
|
|
|
622
824
|
return { status: "signed_in", session };
|
|
623
825
|
}
|
|
624
826
|
var UNAVAILABLE = { status: 503, body: { ok: false, reason: "revocations_unavailable" } };
|
|
827
|
+
var refusedFor = (checked) => checked.status === "signed_out" ? checked.reason : void 0;
|
|
625
828
|
var warnedAudience = false;
|
|
626
829
|
function warnIfAudienceMissing(headers) {
|
|
627
830
|
if (warnedAudience) return;
|
|
@@ -656,6 +859,7 @@ var KNOWN_OPTIONS = /* @__PURE__ */ new Set([
|
|
|
656
859
|
"projectKey",
|
|
657
860
|
"meOrigin",
|
|
658
861
|
"revocation",
|
|
862
|
+
"requireHandle",
|
|
659
863
|
"required",
|
|
660
864
|
"requireBond"
|
|
661
865
|
]);
|
|
@@ -670,6 +874,7 @@ function checkOptions(options) {
|
|
|
670
874
|
`@orangecheck/me-client: unknown option ${unknown.join(", ")}. It reads only ${[...KNOWN_OPTIONS].join(", ")}.`
|
|
671
875
|
);
|
|
672
876
|
}
|
|
877
|
+
checkRequireHandle(options.requireHandle);
|
|
673
878
|
const bond = options.requireBond;
|
|
674
879
|
if (bond === void 0) return;
|
|
675
880
|
if (bond === null || typeof bond !== "object") {
|
|
@@ -752,10 +957,9 @@ async function bondNeed(options) {
|
|
|
752
957
|
if (options.projectKey) return projectRequirement(options);
|
|
753
958
|
return null;
|
|
754
959
|
}
|
|
755
|
-
async function refusal(session, options) {
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
}
|
|
960
|
+
async function refusal(session, options, why) {
|
|
961
|
+
const unauthenticated = { status: 401, body: { ok: false, reason: why ?? "unauthenticated" } };
|
|
962
|
+
if (!session && options.required) return unauthenticated;
|
|
759
963
|
if (!session && !options.requireBond) return null;
|
|
760
964
|
const need = await bondNeed(options);
|
|
761
965
|
if (need === UNKNOWN_PROJECT) {
|
|
@@ -764,9 +968,7 @@ async function refusal(session, options) {
|
|
|
764
968
|
if (need === void 0) {
|
|
765
969
|
return { status: 503, body: { ok: false, reason: "bond_policy_unavailable" } };
|
|
766
970
|
}
|
|
767
|
-
if (!session)
|
|
768
|
-
return need ? { status: 401, body: { ok: false, reason: "unauthenticated" } } : null;
|
|
769
|
-
}
|
|
971
|
+
if (!session) return need ? unauthenticated : null;
|
|
770
972
|
if (need && !authCore.bondMeets(session, need)) {
|
|
771
973
|
const have = authCore.readBondClaim(session);
|
|
772
974
|
return {
|
|
@@ -801,8 +1003,8 @@ function withOcAuth(handler, options = {}) {
|
|
|
801
1003
|
const session = checked.status === "signed_in" ? checked.session : null;
|
|
802
1004
|
const withSession = req;
|
|
803
1005
|
withSession.ocSession = session;
|
|
804
|
-
const
|
|
805
|
-
if (
|
|
1006
|
+
const refused2 = checked.status === "unavailable" ? UNAVAILABLE : await refusal(session, options, refusedFor(checked));
|
|
1007
|
+
if (refused2) return res.status(refused2.status).json(refused2.body);
|
|
806
1008
|
return handler(withSession, res);
|
|
807
1009
|
};
|
|
808
1010
|
}
|
|
@@ -821,9 +1023,9 @@ function ocAuthExpress(options = {}) {
|
|
|
821
1023
|
);
|
|
822
1024
|
const session = checked.status === "signed_in" ? checked.session : null;
|
|
823
1025
|
req.ocSession = session;
|
|
824
|
-
const
|
|
825
|
-
if (
|
|
826
|
-
res.status(
|
|
1026
|
+
const refused2 = checked.status === "unavailable" ? UNAVAILABLE : await refusal(session, options, refusedFor(checked));
|
|
1027
|
+
if (refused2) {
|
|
1028
|
+
res.status(refused2.status).json(refused2.body);
|
|
827
1029
|
return;
|
|
828
1030
|
}
|
|
829
1031
|
next();
|
|
@@ -843,8 +1045,8 @@ function ocAuthHono(options = {}) {
|
|
|
843
1045
|
});
|
|
844
1046
|
const session = checked.status === "signed_in" ? checked.session : null;
|
|
845
1047
|
c.set("ocSession", session);
|
|
846
|
-
const
|
|
847
|
-
if (
|
|
1048
|
+
const refused2 = checked.status === "unavailable" ? UNAVAILABLE : await refusal(session, options, refusedFor(checked));
|
|
1049
|
+
if (refused2) return c.json(refused2.body, refused2.status);
|
|
848
1050
|
await next();
|
|
849
1051
|
};
|
|
850
1052
|
}
|
|
@@ -857,19 +1059,21 @@ Object.defineProperty(exports, "readBondClaim", {
|
|
|
857
1059
|
enumerable: true,
|
|
858
1060
|
get: function () { return authCore.readBondClaim; }
|
|
859
1061
|
});
|
|
860
|
-
Object.defineProperty(exports, "verifyOcToken", {
|
|
861
|
-
enumerable: true,
|
|
862
|
-
get: function () { return authCore.verifyOcToken; }
|
|
863
|
-
});
|
|
864
1062
|
exports.BACK_ACCOUNT_URL = BACK_ACCOUNT_URL;
|
|
1063
|
+
exports.CONNECT_CONSENT_BLURB = CONNECT_CONSENT_BLURB;
|
|
1064
|
+
exports.CONNECT_CONSENT_LABEL = CONNECT_CONSENT_LABEL;
|
|
865
1065
|
exports._resetSessionChecksForTests = _resetSessionChecksForTests;
|
|
866
1066
|
exports.checkOcSession = checkOcSession;
|
|
1067
|
+
exports.connectClaimLink = connectClaimLink;
|
|
1068
|
+
exports.connectDelete = connectDelete;
|
|
1069
|
+
exports.connectProvision = connectProvision;
|
|
867
1070
|
exports.getOcSession = getOcSession;
|
|
868
1071
|
exports.identity = identity;
|
|
869
1072
|
exports.ocAuthExpress = ocAuthExpress;
|
|
870
1073
|
exports.ocAuthHono = ocAuthHono;
|
|
871
1074
|
exports.refreshEnvelopeJwks = refreshEnvelopeJwks;
|
|
872
1075
|
exports.verifyActivityAttestation = verifyActivityAttestation;
|
|
1076
|
+
exports.verifyOcToken = verifyOcToken;
|
|
873
1077
|
exports.withOcAuth = withOcAuth;
|
|
874
1078
|
//# sourceMappingURL=server.js.map
|
|
875
1079
|
//# sourceMappingURL=server.js.map
|