@orangecheck/auth-client 2.20.0 → 2.21.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/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +100 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -156,6 +156,7 @@ declare function OcLinkedIdentities({ authOrigin, className, onChange, }: OcLink
|
|
|
156
156
|
|
|
157
157
|
declare const TAB_SESSION_HEADER = "x-oc-tab-session";
|
|
158
158
|
declare const TAB_SESSION_STORAGE_KEY = "oc_tab_session";
|
|
159
|
+
declare const TAB_ACCOUNT_HINT_KEY = "oc-as";
|
|
159
160
|
declare const TAB_ADOPT_HASH = "#oc-adopt";
|
|
160
161
|
interface OcTabSession {
|
|
161
162
|
token: string;
|
|
@@ -167,6 +168,8 @@ declare function clearTabSession(): void;
|
|
|
167
168
|
declare function tabSessionHeader(): Record<string, string>;
|
|
168
169
|
declare function installTabFetchInterceptor(authOrigin: string): () => void;
|
|
169
170
|
declare function consumeTabAdoptMarker(): boolean;
|
|
171
|
+
declare function installTabLinkDecorator(authOrigin: string): () => void;
|
|
172
|
+
declare function consumeTabAccountHint(authOrigin: string): Promise<string | null>;
|
|
170
173
|
|
|
171
174
|
interface WebAuthnCredentialPublic {
|
|
172
175
|
id: string;
|
|
@@ -250,4 +253,4 @@ declare function handleSudoRequired(body: {
|
|
|
250
253
|
returnTo?: string;
|
|
251
254
|
}): boolean;
|
|
252
255
|
|
|
253
|
-
export { DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, type DisplayIdentity, type DisplayIdentityKind, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, type OcAccountSummary, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcLinkedIdentities, type OcLinkedIdentitiesProps, type OcLinkedIdentity, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type OcSignOutScope, type OcTabSession, type RedirectToSudoArgs, TAB_ADOPT_HASH, TAB_SESSION_HEADER, TAB_SESSION_STORAGE_KEY, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, buildAddAccountUrl, buildSignInUrl, clearTabSession, consumeTabAdoptMarker, fetchOcLinkedIdentities, handleSudoRequired, installTabFetchInterceptor, readTabSession, redirectToSudo, tabSessionHeader, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister, writeTabSession };
|
|
256
|
+
export { DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, type DisplayIdentity, type DisplayIdentityKind, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, type OcAccountSummary, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcLinkedIdentities, type OcLinkedIdentitiesProps, type OcLinkedIdentity, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type OcSignOutScope, type OcTabSession, type RedirectToSudoArgs, TAB_ACCOUNT_HINT_KEY, TAB_ADOPT_HASH, TAB_SESSION_HEADER, TAB_SESSION_STORAGE_KEY, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, buildAddAccountUrl, buildSignInUrl, clearTabSession, consumeTabAccountHint, consumeTabAdoptMarker, fetchOcLinkedIdentities, handleSudoRequired, installTabFetchInterceptor, installTabLinkDecorator, readTabSession, redirectToSudo, tabSessionHeader, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister, writeTabSession };
|
package/dist/index.d.ts
CHANGED
|
@@ -156,6 +156,7 @@ declare function OcLinkedIdentities({ authOrigin, className, onChange, }: OcLink
|
|
|
156
156
|
|
|
157
157
|
declare const TAB_SESSION_HEADER = "x-oc-tab-session";
|
|
158
158
|
declare const TAB_SESSION_STORAGE_KEY = "oc_tab_session";
|
|
159
|
+
declare const TAB_ACCOUNT_HINT_KEY = "oc-as";
|
|
159
160
|
declare const TAB_ADOPT_HASH = "#oc-adopt";
|
|
160
161
|
interface OcTabSession {
|
|
161
162
|
token: string;
|
|
@@ -167,6 +168,8 @@ declare function clearTabSession(): void;
|
|
|
167
168
|
declare function tabSessionHeader(): Record<string, string>;
|
|
168
169
|
declare function installTabFetchInterceptor(authOrigin: string): () => void;
|
|
169
170
|
declare function consumeTabAdoptMarker(): boolean;
|
|
171
|
+
declare function installTabLinkDecorator(authOrigin: string): () => void;
|
|
172
|
+
declare function consumeTabAccountHint(authOrigin: string): Promise<string | null>;
|
|
170
173
|
|
|
171
174
|
interface WebAuthnCredentialPublic {
|
|
172
175
|
id: string;
|
|
@@ -250,4 +253,4 @@ declare function handleSudoRequired(body: {
|
|
|
250
253
|
returnTo?: string;
|
|
251
254
|
}): boolean;
|
|
252
255
|
|
|
253
|
-
export { DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, type DisplayIdentity, type DisplayIdentityKind, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, type OcAccountSummary, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcLinkedIdentities, type OcLinkedIdentitiesProps, type OcLinkedIdentity, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type OcSignOutScope, type OcTabSession, type RedirectToSudoArgs, TAB_ADOPT_HASH, TAB_SESSION_HEADER, TAB_SESSION_STORAGE_KEY, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, buildAddAccountUrl, buildSignInUrl, clearTabSession, consumeTabAdoptMarker, fetchOcLinkedIdentities, handleSudoRequired, installTabFetchInterceptor, readTabSession, redirectToSudo, tabSessionHeader, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister, writeTabSession };
|
|
256
|
+
export { DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, type DisplayIdentity, type DisplayIdentityKind, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, type OcAccountSummary, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcLinkedIdentities, type OcLinkedIdentitiesProps, type OcLinkedIdentity, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type OcSignOutScope, type OcTabSession, type RedirectToSudoArgs, TAB_ACCOUNT_HINT_KEY, TAB_ADOPT_HASH, TAB_SESSION_HEADER, TAB_SESSION_STORAGE_KEY, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, buildAddAccountUrl, buildSignInUrl, clearTabSession, consumeTabAccountHint, consumeTabAdoptMarker, fetchOcLinkedIdentities, handleSudoRequired, installTabFetchInterceptor, installTabLinkDecorator, readTabSession, redirectToSudo, tabSessionHeader, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister, writeTabSession };
|
package/dist/index.js
CHANGED
|
@@ -53,6 +53,7 @@ function buildAddAccountUrl(cfg, returnTo) {
|
|
|
53
53
|
// src/tab-session.ts
|
|
54
54
|
var TAB_SESSION_HEADER = "x-oc-tab-session";
|
|
55
55
|
var TAB_SESSION_STORAGE_KEY = "oc_tab_session";
|
|
56
|
+
var TAB_ACCOUNT_HINT_KEY = "oc-as";
|
|
56
57
|
var TAB_ADOPT_HASH = "#oc-adopt";
|
|
57
58
|
function readTabSession() {
|
|
58
59
|
if (typeof window === "undefined") return null;
|
|
@@ -134,6 +135,92 @@ function consumeTabAdoptMarker() {
|
|
|
134
135
|
}
|
|
135
136
|
return true;
|
|
136
137
|
}
|
|
138
|
+
var OC_AS_HINT_RE = /^oc-as=(did:oc:[0-9a-f]{32})$/;
|
|
139
|
+
function familyApex(authOrigin) {
|
|
140
|
+
try {
|
|
141
|
+
return new URL(authOrigin).hostname.toLowerCase();
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function isFamilyUrl(u, authOrigin) {
|
|
147
|
+
if (u.protocol !== "http:" && u.protocol !== "https:") return false;
|
|
148
|
+
if (typeof window !== "undefined" && u.origin === window.location.origin) return true;
|
|
149
|
+
const apex = familyApex(authOrigin);
|
|
150
|
+
if (!apex) return false;
|
|
151
|
+
const host = u.hostname.toLowerCase();
|
|
152
|
+
return host === apex || host.endsWith(`.${apex}`);
|
|
153
|
+
}
|
|
154
|
+
function opensWithoutTabPin(e, anchor, dest) {
|
|
155
|
+
if (typeof window !== "undefined" && dest.origin !== window.location.origin) return true;
|
|
156
|
+
const target = (anchor.getAttribute("target") ?? "").toLowerCase();
|
|
157
|
+
return e.button === 1 || // middle-click
|
|
158
|
+
e.metaKey || e.ctrlKey || e.shiftKey || target === "_blank";
|
|
159
|
+
}
|
|
160
|
+
function installTabLinkDecorator(authOrigin) {
|
|
161
|
+
if (typeof window === "undefined" || typeof document === "undefined") return () => {
|
|
162
|
+
};
|
|
163
|
+
const onActivate = (e) => {
|
|
164
|
+
try {
|
|
165
|
+
const pin = readTabSession();
|
|
166
|
+
if (!pin) return;
|
|
167
|
+
const target = e.target;
|
|
168
|
+
if (!(target instanceof Element)) return;
|
|
169
|
+
const anchor = target.closest("a[href]");
|
|
170
|
+
if (!anchor || anchor.hasAttribute("download")) return;
|
|
171
|
+
const raw = anchor.getAttribute("href");
|
|
172
|
+
if (!raw || raw.includes(`${TAB_ACCOUNT_HINT_KEY}=`)) return;
|
|
173
|
+
let dest;
|
|
174
|
+
try {
|
|
175
|
+
dest = new URL(anchor.href);
|
|
176
|
+
} catch {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (dest.hash) return;
|
|
180
|
+
if (!isFamilyUrl(dest, authOrigin)) return;
|
|
181
|
+
if (!opensWithoutTabPin(e, anchor, dest)) return;
|
|
182
|
+
anchor.setAttribute("href", `${raw}#${TAB_ACCOUNT_HINT_KEY}=${pin.didOc}`);
|
|
183
|
+
} catch {
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
window.addEventListener("click", onActivate, true);
|
|
187
|
+
window.addEventListener("auxclick", onActivate, true);
|
|
188
|
+
return () => {
|
|
189
|
+
window.removeEventListener("click", onActivate, true);
|
|
190
|
+
window.removeEventListener("auxclick", onActivate, true);
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
async function consumeTabAccountHint(authOrigin) {
|
|
194
|
+
if (typeof window === "undefined") return null;
|
|
195
|
+
const frag = window.location.hash.replace(/^#/, "");
|
|
196
|
+
const m = OC_AS_HINT_RE.exec(frag);
|
|
197
|
+
if (!m) return null;
|
|
198
|
+
const did = m[1];
|
|
199
|
+
try {
|
|
200
|
+
const url = new URL(window.location.href);
|
|
201
|
+
url.hash = "";
|
|
202
|
+
window.history.replaceState(window.history.state, "", url.toString());
|
|
203
|
+
} catch {
|
|
204
|
+
}
|
|
205
|
+
const existing = readTabSession();
|
|
206
|
+
if (existing && existing.didOc === did) return did;
|
|
207
|
+
try {
|
|
208
|
+
const res = await fetch(`${authOrigin}/api/auth/tab`, {
|
|
209
|
+
method: "POST",
|
|
210
|
+
credentials: "include",
|
|
211
|
+
headers: { Accept: "application/json", "Content-Type": "application/json" },
|
|
212
|
+
body: JSON.stringify({ did_oc: did })
|
|
213
|
+
});
|
|
214
|
+
if (!res.ok) return null;
|
|
215
|
+
const body = await res.json();
|
|
216
|
+
if (body.ok && typeof body.token === "string" && body.account?.did_oc === did) {
|
|
217
|
+
writeTabSession({ token: body.token, didOc: did });
|
|
218
|
+
return did;
|
|
219
|
+
}
|
|
220
|
+
} catch {
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
137
224
|
var SessionContext = React3__namespace.createContext(null);
|
|
138
225
|
function normalizeDisplayIdentity(raw, didOc) {
|
|
139
226
|
const di = raw.display_identity ?? raw.displayIdentity;
|
|
@@ -277,10 +364,18 @@ function OcSessionProvider({
|
|
|
277
364
|
}
|
|
278
365
|
}, [cfg, pinThisTab]);
|
|
279
366
|
React3__namespace.useEffect(() => {
|
|
367
|
+
let cancelled = false;
|
|
280
368
|
consumeTabAdoptMarker();
|
|
281
|
-
void
|
|
282
|
-
|
|
369
|
+
void (async () => {
|
|
370
|
+
await consumeTabAccountHint(cfg.authOrigin);
|
|
371
|
+
if (!cancelled) void refresh();
|
|
372
|
+
})();
|
|
373
|
+
return () => {
|
|
374
|
+
cancelled = true;
|
|
375
|
+
};
|
|
376
|
+
}, [refresh, cfg.authOrigin]);
|
|
283
377
|
React3__namespace.useEffect(() => installTabFetchInterceptor(cfg.authOrigin), [cfg.authOrigin]);
|
|
378
|
+
React3__namespace.useEffect(() => installTabLinkDecorator(cfg.authOrigin), [cfg.authOrigin]);
|
|
284
379
|
const signOut = React3__namespace.useCallback(
|
|
285
380
|
async (opts) => {
|
|
286
381
|
const scope = opts?.scope ?? "all";
|
|
@@ -3022,16 +3117,19 @@ exports.OcLinkedIdentities = OcLinkedIdentities;
|
|
|
3022
3117
|
exports.OcSessionProvider = OcSessionProvider;
|
|
3023
3118
|
exports.OcSignIn = OcSignIn;
|
|
3024
3119
|
exports.OcSignInButton = OcSignInButton;
|
|
3120
|
+
exports.TAB_ACCOUNT_HINT_KEY = TAB_ACCOUNT_HINT_KEY;
|
|
3025
3121
|
exports.TAB_ADOPT_HASH = TAB_ADOPT_HASH;
|
|
3026
3122
|
exports.TAB_SESSION_HEADER = TAB_SESSION_HEADER;
|
|
3027
3123
|
exports.TAB_SESSION_STORAGE_KEY = TAB_SESSION_STORAGE_KEY;
|
|
3028
3124
|
exports.buildAddAccountUrl = buildAddAccountUrl;
|
|
3029
3125
|
exports.buildSignInUrl = buildSignInUrl;
|
|
3030
3126
|
exports.clearTabSession = clearTabSession;
|
|
3127
|
+
exports.consumeTabAccountHint = consumeTabAccountHint;
|
|
3031
3128
|
exports.consumeTabAdoptMarker = consumeTabAdoptMarker;
|
|
3032
3129
|
exports.fetchOcLinkedIdentities = fetchOcLinkedIdentities;
|
|
3033
3130
|
exports.handleSudoRequired = handleSudoRequired;
|
|
3034
3131
|
exports.installTabFetchInterceptor = installTabFetchInterceptor;
|
|
3132
|
+
exports.installTabLinkDecorator = installTabLinkDecorator;
|
|
3035
3133
|
exports.readTabSession = readTabSession;
|
|
3036
3134
|
exports.redirectToSudo = redirectToSudo;
|
|
3037
3135
|
exports.tabSessionHeader = tabSessionHeader;
|