@orangecheck/me-client 0.43.0 → 0.45.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 +2 -0
- package/dist/server.d.mts +17 -1
- package/dist/server.d.ts +17 -1
- package/dist/server.js +38 -5
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +38 -7
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -271,6 +271,8 @@ app.get('/api/me', (c) => {
|
|
|
271
271
|
|
|
272
272
|
### Sessions ended everywhere
|
|
273
273
|
|
|
274
|
+
A *.ochk.io site that reads the family cookie (no `audience`) sees family sessions, which ochk.io ends on its own feed. Set `OC_REVOCATION_FEED_TOKEN` (the site's feed token from ochk.io) and the helpers check every family session against it, once a minute per process; while the feed can't be read, reads go on and writes answer 503. With it unset, a family session makes them throw rather than accept it by signature alone (0.44.0); `revocation: false` reads it by signature alone on purpose. The feed is read from `OC_AUTH_ISSUER` (default https://ochk.io), so set it too if you verify another issuer.
|
|
275
|
+
|
|
274
276
|
Set `OC_PROJECT_KEY` and `OC_SIGNING_SECRET` (from ochk.app/me/projects) and `getOcSession`, `withOcAuth`, `ocAuthExpress` and `ocAuthHono` refuse a session the person ended everywhere: sign out everywhere, a passkey removed, the account deleted. A sign-in token carries `rh`, its revocation handle for your origin; they look it up in me.ochk.io's list of ended handles for that origin, read once a minute per origin with a request signed by your secret, so a refusal lands within about two minutes. The handles name nobody, and another site's handles for the same person never match yours. If the list can't be read, or is more than ten minutes old by its own clock, reads go on and writes are refused until it can: the adapters answer such a write `503 { reason: 'revocations_unavailable' }` (0.38.0), not 401, so a client retries instead of signing the person out, and `checkOcSession(headers, options)` tells the same apart for your own code (`signed_in`, `signed_out` or `unavailable`). Every token while the two variables are unset is checked by its signature alone and stays valid until it expires. A token bound to your site without `rh` is refused (`no_session_handle`, 0.40.0 or later), since sign out everywhere can't reach it; every token from the sign-in popup carries one, and `requireHandle: false` accepts one minted some other way. Needs 0.35.0 or later.
|
|
275
277
|
|
|
276
278
|
## Keep your own login: OC Connect
|
package/dist/server.d.mts
CHANGED
|
@@ -62,6 +62,22 @@ type RevokeTokenResult = {
|
|
|
62
62
|
};
|
|
63
63
|
declare function revokeToken(token: string | readonly string[], options?: RevokeTokenOptions): Promise<RevokeTokenResult>;
|
|
64
64
|
|
|
65
|
+
type MergedUserMatch = {
|
|
66
|
+
kind: 'none';
|
|
67
|
+
} | {
|
|
68
|
+
kind: 'one';
|
|
69
|
+
user: string;
|
|
70
|
+
} | {
|
|
71
|
+
kind: 'conflict';
|
|
72
|
+
users: string[];
|
|
73
|
+
};
|
|
74
|
+
declare function mergedHandles(session: {
|
|
75
|
+
merged_rh?: unknown;
|
|
76
|
+
}): string[];
|
|
77
|
+
declare function matchMergedUser(session: {
|
|
78
|
+
merged_rh?: unknown;
|
|
79
|
+
}, lookup: (rh: string) => string | null | undefined | Promise<string | null | undefined>): Promise<MergedUserMatch>;
|
|
80
|
+
|
|
65
81
|
type OcSessionRefusal = 'no_session_handle';
|
|
66
82
|
interface VerifyOcTokenOptions extends VerifyOcOptions {
|
|
67
83
|
requireHandle?: boolean;
|
|
@@ -182,4 +198,4 @@ interface HonoContextLike {
|
|
|
182
198
|
type HonoNextLike = () => Promise<void>;
|
|
183
199
|
declare function ocAuthHono(options?: WithOcAuthOptions): (c: HonoContextLike, next: HonoNextLike) => Promise<unknown>;
|
|
184
200
|
|
|
185
|
-
export { BACK_ACCOUNT_URL, type ConnectClaimLinkRefusal, type ConnectClaimLinkResult, type ConnectDeleteRefusal, type ConnectDeleteResult, type ConnectOptions, type ConnectProvisionOptions, type ConnectProvisionRefusal, type ConnectProvisionResult, type ConnectRefused, type JtiStore, MemoryJtiStore, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type OcSessionRefusal, type OcSessionUnavailable, type OcTokenCheck, type RevokeTokenOptions, type RevokeTokenRefusal, type RevokeTokenResult, type SignInRuleCheck, type SignInRuleOptions, type VerifyOcTokenOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, checkOcToken, checkSignInRule, connectClaimLink, connectDelete, connectProvision, getOcSession, ocAuthExpress, ocAuthHono, revokeToken, spendOnce, verifyOcToken, withOcAuth };
|
|
201
|
+
export { BACK_ACCOUNT_URL, type ConnectClaimLinkRefusal, type ConnectClaimLinkResult, type ConnectDeleteRefusal, type ConnectDeleteResult, type ConnectOptions, type ConnectProvisionOptions, type ConnectProvisionRefusal, type ConnectProvisionResult, type ConnectRefused, type JtiStore, MemoryJtiStore, type MergedUserMatch, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type OcSessionRefusal, type OcSessionUnavailable, type OcTokenCheck, type RevokeTokenOptions, type RevokeTokenRefusal, type RevokeTokenResult, type SignInRuleCheck, type SignInRuleOptions, type VerifyOcTokenOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, checkOcToken, checkSignInRule, connectClaimLink, connectDelete, connectProvision, getOcSession, matchMergedUser, mergedHandles, ocAuthExpress, ocAuthHono, revokeToken, spendOnce, verifyOcToken, withOcAuth };
|
package/dist/server.d.ts
CHANGED
|
@@ -62,6 +62,22 @@ type RevokeTokenResult = {
|
|
|
62
62
|
};
|
|
63
63
|
declare function revokeToken(token: string | readonly string[], options?: RevokeTokenOptions): Promise<RevokeTokenResult>;
|
|
64
64
|
|
|
65
|
+
type MergedUserMatch = {
|
|
66
|
+
kind: 'none';
|
|
67
|
+
} | {
|
|
68
|
+
kind: 'one';
|
|
69
|
+
user: string;
|
|
70
|
+
} | {
|
|
71
|
+
kind: 'conflict';
|
|
72
|
+
users: string[];
|
|
73
|
+
};
|
|
74
|
+
declare function mergedHandles(session: {
|
|
75
|
+
merged_rh?: unknown;
|
|
76
|
+
}): string[];
|
|
77
|
+
declare function matchMergedUser(session: {
|
|
78
|
+
merged_rh?: unknown;
|
|
79
|
+
}, lookup: (rh: string) => string | null | undefined | Promise<string | null | undefined>): Promise<MergedUserMatch>;
|
|
80
|
+
|
|
65
81
|
type OcSessionRefusal = 'no_session_handle';
|
|
66
82
|
interface VerifyOcTokenOptions extends VerifyOcOptions {
|
|
67
83
|
requireHandle?: boolean;
|
|
@@ -182,4 +198,4 @@ interface HonoContextLike {
|
|
|
182
198
|
type HonoNextLike = () => Promise<void>;
|
|
183
199
|
declare function ocAuthHono(options?: WithOcAuthOptions): (c: HonoContextLike, next: HonoNextLike) => Promise<unknown>;
|
|
184
200
|
|
|
185
|
-
export { BACK_ACCOUNT_URL, type ConnectClaimLinkRefusal, type ConnectClaimLinkResult, type ConnectDeleteRefusal, type ConnectDeleteResult, type ConnectOptions, type ConnectProvisionOptions, type ConnectProvisionRefusal, type ConnectProvisionResult, type ConnectRefused, type JtiStore, MemoryJtiStore, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type OcSessionRefusal, type OcSessionUnavailable, type OcTokenCheck, type RevokeTokenOptions, type RevokeTokenRefusal, type RevokeTokenResult, type SignInRuleCheck, type SignInRuleOptions, type VerifyOcTokenOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, checkOcToken, checkSignInRule, connectClaimLink, connectDelete, connectProvision, getOcSession, ocAuthExpress, ocAuthHono, revokeToken, spendOnce, verifyOcToken, withOcAuth };
|
|
201
|
+
export { BACK_ACCOUNT_URL, type ConnectClaimLinkRefusal, type ConnectClaimLinkResult, type ConnectDeleteRefusal, type ConnectDeleteResult, type ConnectOptions, type ConnectProvisionOptions, type ConnectProvisionRefusal, type ConnectProvisionResult, type ConnectRefused, type JtiStore, MemoryJtiStore, type MergedUserMatch, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type OcSessionRefusal, type OcSessionUnavailable, type OcTokenCheck, type RevokeTokenOptions, type RevokeTokenRefusal, type RevokeTokenResult, type SignInRuleCheck, type SignInRuleOptions, type VerifyOcTokenOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, checkOcToken, checkSignInRule, connectClaimLink, connectDelete, connectProvision, getOcSession, matchMergedUser, mergedHandles, ocAuthExpress, ocAuthHono, revokeToken, spendOnce, verifyOcToken, withOcAuth };
|
package/dist/server.js
CHANGED
|
@@ -837,16 +837,38 @@ async function post2(url, tokens, timeoutMs) {
|
|
|
837
837
|
}
|
|
838
838
|
}
|
|
839
839
|
|
|
840
|
+
// src/merged.ts
|
|
841
|
+
var MERGED_HANDLES_MAX = 16;
|
|
842
|
+
function mergedHandles(session) {
|
|
843
|
+
const v = session.merged_rh;
|
|
844
|
+
if (!Array.isArray(v) || v.length > MERGED_HANDLES_MAX) return [];
|
|
845
|
+
if (!v.every((h) => typeof h === "string" && h.length > 0)) return [];
|
|
846
|
+
return [...new Set(v)];
|
|
847
|
+
}
|
|
848
|
+
async function matchMergedUser(session, lookup) {
|
|
849
|
+
const users = /* @__PURE__ */ new Set();
|
|
850
|
+
for (const rh of mergedHandles(session)) {
|
|
851
|
+
const user = await lookup(rh);
|
|
852
|
+
if (typeof user === "string" && user.length > 0) users.add(user);
|
|
853
|
+
}
|
|
854
|
+
if (users.size === 0) return { kind: "none" };
|
|
855
|
+
if (users.size === 1) return { kind: "one", user: [...users][0] };
|
|
856
|
+
return { kind: "conflict", users: [...users].sort() };
|
|
857
|
+
}
|
|
858
|
+
|
|
840
859
|
// src/server.ts
|
|
841
860
|
var VERIFIED = /* @__PURE__ */ new WeakSet();
|
|
842
861
|
function vouch(session) {
|
|
843
862
|
VERIFIED.add(session);
|
|
844
863
|
return session;
|
|
845
864
|
}
|
|
865
|
+
function isFamily(session) {
|
|
866
|
+
const aud = session.aud;
|
|
867
|
+
return aud === void 0 || Array.isArray(aud) && aud.length === 0;
|
|
868
|
+
}
|
|
846
869
|
function lacksHandle(session, requireHandle) {
|
|
847
|
-
if (requireHandle === false) return false;
|
|
848
|
-
const
|
|
849
|
-
if (aud === void 0) return false;
|
|
870
|
+
if (requireHandle === false || isFamily(session)) return false;
|
|
871
|
+
const rh = session.rh;
|
|
850
872
|
return typeof rh !== "string" || rh.length === 0;
|
|
851
873
|
}
|
|
852
874
|
function checkRequireHandle(requireHandle) {
|
|
@@ -893,9 +915,18 @@ async function checkOcToken(token, options = {}) {
|
|
|
893
915
|
}
|
|
894
916
|
var sessionChecks = /* @__PURE__ */ new Map();
|
|
895
917
|
var warnedUnchecked = false;
|
|
896
|
-
function revocationFor(options) {
|
|
918
|
+
function revocationFor(options, session) {
|
|
897
919
|
if (options.revocation === false) return null;
|
|
898
920
|
if (options.revocation) return options.revocation;
|
|
921
|
+
if (isFamily(session)) {
|
|
922
|
+
const token = typeof process !== "undefined" ? process.env?.OC_REVOCATION_FEED_TOKEN?.trim() : void 0;
|
|
923
|
+
if (!token) {
|
|
924
|
+
throw new Error(
|
|
925
|
+
"@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."
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
return authCore.familyRevocationCheck();
|
|
929
|
+
}
|
|
899
930
|
const key = `${options.meOrigin ?? ""} ${options.projectKey ?? ""}`;
|
|
900
931
|
if (!sessionChecks.has(key)) {
|
|
901
932
|
sessionChecks.set(
|
|
@@ -941,7 +972,7 @@ async function checkOcSession(headers, options = {}) {
|
|
|
941
972
|
warnNoHandle(session);
|
|
942
973
|
return { status: "signed_out", reason: "no_session_handle" };
|
|
943
974
|
}
|
|
944
|
-
const check = revocationFor(options);
|
|
975
|
+
const check = revocationFor(options, session);
|
|
945
976
|
if (check) {
|
|
946
977
|
const state = await check.status(session);
|
|
947
978
|
if (state === "revoked") return { status: "signed_out" };
|
|
@@ -1230,6 +1261,8 @@ exports.connectDelete = connectDelete;
|
|
|
1230
1261
|
exports.connectProvision = connectProvision;
|
|
1231
1262
|
exports.getOcSession = getOcSession;
|
|
1232
1263
|
exports.identity = identity;
|
|
1264
|
+
exports.matchMergedUser = matchMergedUser;
|
|
1265
|
+
exports.mergedHandles = mergedHandles;
|
|
1233
1266
|
exports.ocAuthExpress = ocAuthExpress;
|
|
1234
1267
|
exports.ocAuthHono = ocAuthHono;
|
|
1235
1268
|
exports.refreshEnvelopeJwks = refreshEnvelopeJwks;
|