@oxyhq/services 21.0.0 → 22.0.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/lib/commonjs/index.js +13 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/ui/boot/runProviderColdBoot.js +12 -2
- package/lib/commonjs/ui/boot/runProviderColdBoot.js.map +1 -1
- package/lib/commonjs/ui/components/OxyAccountDialog.js +46 -19
- package/lib/commonjs/ui/components/OxyAccountDialog.js.map +1 -1
- package/lib/commonjs/ui/components/OxyProvider.js +2 -0
- package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
- package/lib/commonjs/ui/context/OxyContext.js +80 -59
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/context/passkeyFlow.js +118 -0
- package/lib/commonjs/ui/context/passkeyFlow.js.map +1 -0
- package/lib/commonjs/ui/hooks/queries/queryKeys.js +18 -2
- package/lib/commonjs/ui/hooks/queries/queryKeys.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/useAuthMethods.js +49 -0
- package/lib/commonjs/ui/hooks/queries/useAuthMethods.js.map +1 -0
- package/lib/commonjs/ui/utils/crossOriginRestore.js +26 -0
- package/lib/commonjs/ui/utils/crossOriginRestore.js.map +1 -1
- package/lib/commonjs/webauthn/passkeyClient.js +39 -0
- package/lib/commonjs/webauthn/passkeyClient.js.map +1 -0
- package/lib/commonjs/webauthn/passkeyClient.native.js +34 -0
- package/lib/commonjs/webauthn/passkeyClient.native.js.map +1 -0
- package/lib/commonjs/webauthn/passkeyClient.web.js +57 -0
- package/lib/commonjs/webauthn/passkeyClient.web.js.map +1 -0
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/ui/boot/runProviderColdBoot.js +13 -3
- package/lib/module/ui/boot/runProviderColdBoot.js.map +1 -1
- package/lib/module/ui/components/OxyAccountDialog.js +46 -19
- package/lib/module/ui/components/OxyAccountDialog.js.map +1 -1
- package/lib/module/ui/components/OxyProvider.js +2 -0
- package/lib/module/ui/components/OxyProvider.js.map +1 -1
- package/lib/module/ui/context/OxyContext.js +80 -59
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/context/passkeyFlow.js +111 -0
- package/lib/module/ui/context/passkeyFlow.js.map +1 -0
- package/lib/module/ui/hooks/queries/queryKeys.js +15 -0
- package/lib/module/ui/hooks/queries/queryKeys.js.map +1 -1
- package/lib/module/ui/hooks/queries/useAuthMethods.js +45 -0
- package/lib/module/ui/hooks/queries/useAuthMethods.js.map +1 -0
- package/lib/module/ui/utils/crossOriginRestore.js +26 -1
- package/lib/module/ui/utils/crossOriginRestore.js.map +1 -1
- package/lib/module/webauthn/passkeyClient.js +33 -0
- package/lib/module/webauthn/passkeyClient.js.map +1 -0
- package/lib/module/webauthn/passkeyClient.native.js +28 -0
- package/lib/module/webauthn/passkeyClient.native.js.map +1 -0
- package/lib/module/webauthn/passkeyClient.web.js +52 -0
- package/lib/module/webauthn/passkeyClient.web.js.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +3 -2
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/boot/runProviderColdBoot.d.ts +6 -0
- package/lib/typescript/commonjs/ui/boot/runProviderColdBoot.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/OxyAccountDialog.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/context/OxyContext.d.ts +1 -1
- package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts +41 -20
- package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/context/passkeyFlow.d.ts +96 -0
- package/lib/typescript/commonjs/ui/context/passkeyFlow.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/mutations/useAccountMutations.d.ts +2 -2
- package/lib/typescript/commonjs/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/queries/queryKeys.d.ts +9 -0
- package/lib/typescript/commonjs/ui/hooks/queries/queryKeys.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/queries/useAuthMethods.d.ts +212 -0
- package/lib/typescript/commonjs/ui/hooks/queries/useAuthMethods.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/types/navigation.d.ts +8 -0
- package/lib/typescript/commonjs/ui/types/navigation.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/utils/crossOriginRestore.d.ts +19 -0
- package/lib/typescript/commonjs/ui/utils/crossOriginRestore.d.ts.map +1 -1
- package/lib/typescript/commonjs/webauthn/passkeyClient.d.ts +20 -0
- package/lib/typescript/commonjs/webauthn/passkeyClient.d.ts.map +1 -0
- package/lib/typescript/commonjs/webauthn/passkeyClient.native.d.ts +15 -0
- package/lib/typescript/commonjs/webauthn/passkeyClient.native.d.ts.map +1 -0
- package/lib/typescript/commonjs/webauthn/passkeyClient.web.d.ts +36 -0
- package/lib/typescript/commonjs/webauthn/passkeyClient.web.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +3 -2
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/boot/runProviderColdBoot.d.ts +6 -0
- package/lib/typescript/module/ui/boot/runProviderColdBoot.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/OxyAccountDialog.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/OxyProvider.d.ts.map +1 -1
- package/lib/typescript/module/ui/context/OxyContext.d.ts +1 -1
- package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/module/ui/context/oxyContextTypes.d.ts +41 -20
- package/lib/typescript/module/ui/context/oxyContextTypes.d.ts.map +1 -1
- package/lib/typescript/module/ui/context/passkeyFlow.d.ts +96 -0
- package/lib/typescript/module/ui/context/passkeyFlow.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/mutations/useAccountMutations.d.ts +2 -2
- package/lib/typescript/module/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/queries/queryKeys.d.ts +9 -0
- package/lib/typescript/module/ui/hooks/queries/queryKeys.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/queries/useAuthMethods.d.ts +212 -0
- package/lib/typescript/module/ui/hooks/queries/useAuthMethods.d.ts.map +1 -0
- package/lib/typescript/module/ui/types/navigation.d.ts +8 -0
- package/lib/typescript/module/ui/types/navigation.d.ts.map +1 -1
- package/lib/typescript/module/ui/utils/crossOriginRestore.d.ts +19 -0
- package/lib/typescript/module/ui/utils/crossOriginRestore.d.ts.map +1 -1
- package/lib/typescript/module/webauthn/passkeyClient.d.ts +20 -0
- package/lib/typescript/module/webauthn/passkeyClient.d.ts.map +1 -0
- package/lib/typescript/module/webauthn/passkeyClient.native.d.ts +15 -0
- package/lib/typescript/module/webauthn/passkeyClient.native.d.ts.map +1 -0
- package/lib/typescript/module/webauthn/passkeyClient.web.d.ts +36 -0
- package/lib/typescript/module/webauthn/passkeyClient.web.d.ts.map +1 -0
- package/package.json +6 -5
- package/src/index.ts +3 -1
- package/src/ui/boot/runProviderColdBoot.ts +24 -1
- package/src/ui/components/OxyAccountDialog.tsx +57 -14
- package/src/ui/components/OxyProvider.tsx +2 -0
- package/src/ui/context/OxyContext.tsx +85 -63
- package/src/ui/context/__tests__/passkeyFlow.test.ts +244 -0
- package/src/ui/context/oxyContextTypes.ts +41 -19
- package/src/ui/context/passkeyFlow.ts +154 -0
- package/src/ui/hooks/queries/queryKeys.ts +14 -0
- package/src/ui/hooks/queries/useAuthMethods.ts +45 -0
- package/src/ui/types/navigation.ts +8 -0
- package/src/ui/utils/__tests__/crossOriginRestore.test.ts +143 -0
- package/src/ui/utils/crossOriginRestore.ts +34 -0
- package/src/webauthn/passkeyClient.native.ts +26 -0
- package/src/webauthn/passkeyClient.ts +31 -0
- package/src/webauthn/passkeyClient.web.ts +56 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { OxyServices, User, SessionLoginResponse, AccountNode, CreateAccountInput, ClientSession, AccountDialogController, AccountDialogView, ApiError, SessionClient } from '@oxyhq/core';
|
|
3
|
-
import type { SecurityAlert } from '@oxyhq/contracts';
|
|
4
3
|
import type { UseFollowHook } from '../hooks/useFollow.types';
|
|
5
4
|
import type { useLanguageManagement } from '../hooks/useLanguageManagement';
|
|
6
5
|
import type { RouteName } from '../navigation/routes';
|
|
@@ -41,18 +40,41 @@ export interface OxyContextState {
|
|
|
41
40
|
|
|
42
41
|
signIn: (publicKey: string, deviceName?: string) => Promise<User>;
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Sign in with a passkey (WebAuthn). With no `username` this is the
|
|
45
|
+
* usernameless / discoverable-credential flow: the browser prompts for any
|
|
46
|
+
* resident Oxy passkey. Pass `username` for the username-first flow — the
|
|
47
|
+
* server scopes `allowCredentials` to that user's passkeys so a
|
|
48
|
+
* NON-discoverable hardware key (e.g. a U2F/security key) can be used.
|
|
49
|
+
* WEB-ONLY — throws on native or an unsupported browser (native passkeys are
|
|
50
|
+
* Commons' job). On `useOxy()`, NOT re-exposed on `useAuth()`.
|
|
51
|
+
*/
|
|
52
|
+
signInWithPasskey: (opts?: {
|
|
53
|
+
username?: string;
|
|
54
54
|
deviceName?: string;
|
|
55
|
-
|
|
55
|
+
deviceFingerprint?: string;
|
|
56
|
+
}) => Promise<void>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Create a brand-new account whose first authentication method is a passkey.
|
|
60
|
+
* WEB-ONLY — throws on native or an unsupported browser.
|
|
61
|
+
*/
|
|
62
|
+
registerWithPasskey: (params: { username: string; deviceName?: string }) => Promise<void>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Add a passkey to the already-signed-in account (bearer present). Does NOT
|
|
66
|
+
* commit a new session; refreshes the linked auth-methods list on success.
|
|
67
|
+
* WEB-ONLY — throws on native or an unsupported browser.
|
|
68
|
+
*/
|
|
69
|
+
addPasskey: (params?: { deviceName?: string }) => Promise<void>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Remove a passkey from the current account by its credential id
|
|
73
|
+
* (`AuthMethodEntry.credentialId`). Refreshes the linked auth-methods list on
|
|
74
|
+
* success. Works on any platform (it is a plain unlink, not a WebAuthn
|
|
75
|
+
* ceremony) but is only reachable from surfaces that list passkeys.
|
|
76
|
+
*/
|
|
77
|
+
removePasskey: (credentialId: string) => Promise<void>;
|
|
56
78
|
|
|
57
79
|
revokeSuspiciousSignIn: () => Promise<void>;
|
|
58
80
|
handleWebSession: (session: SessionLoginResponse) => Promise<void>;
|
|
@@ -96,19 +118,19 @@ export interface OxyContextState {
|
|
|
96
118
|
createAccount: (data: CreateAccountInput) => Promise<AccountNode>;
|
|
97
119
|
}
|
|
98
120
|
|
|
99
|
-
/**
|
|
100
|
-
* Result of {@link OxyContextState.signInWithPassword}.
|
|
101
|
-
*/
|
|
102
|
-
export type PasswordSignInResult =
|
|
103
|
-
| { status: 'ok'; securityAlert?: SecurityAlert }
|
|
104
|
-
| { status: '2fa_required'; loginToken: string };
|
|
105
|
-
|
|
106
121
|
export interface OxyContextProviderProps {
|
|
107
122
|
children: ReactNode;
|
|
108
123
|
oxyServices?: OxyServices;
|
|
109
124
|
baseURL?: string;
|
|
110
125
|
authWebUrl?: string;
|
|
111
126
|
authRedirectUri?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Authorize endpoint override for silent cross-origin session restore
|
|
129
|
+
* (web cross-app SSO). Defaults to the production Oxy IdP when unset; a
|
|
130
|
+
* local/staging deployment points it at its own IdP so cold boot never
|
|
131
|
+
* bounces the tab to production `auth.oxy.so`.
|
|
132
|
+
*/
|
|
133
|
+
authorizeBaseUrl?: string;
|
|
112
134
|
storageKeyPrefix?: string;
|
|
113
135
|
clientId?: string;
|
|
114
136
|
/** Sync device credentials to auth.oxy.so after interactive sign-in. @default true */
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure passkey (WebAuthn) sign-in / registration orchestration.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `OxyContext` so the fixed `options → ceremony → verify → commit`
|
|
5
|
+
* ordering is unit-testable with injected deps — the exact pattern
|
|
6
|
+
* `commitSessionFlow.ts` (`commitDeviceSetAndResolve`) uses. The context methods
|
|
7
|
+
* (`signInWithPasskey` / `registerWithPasskey` / `addPasskey`) are thin wrappers
|
|
8
|
+
* that supply the real deps: the core `webauthn*` methods, the platform ceremony
|
|
9
|
+
* client (`webauthn/passkeyClient`), and the internal `commitSession` funnel.
|
|
10
|
+
*
|
|
11
|
+
* All three GATE on `isSupported()` first (the platform client returns `false`
|
|
12
|
+
* off the web) so an unsupported surface fails loudly before touching a ceremony.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { LoginResult, LoginSessionResult } from '@oxyhq/contracts';
|
|
16
|
+
import type { CommitInput } from './oxyContextTypes';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The result of `OxyServices.webauthnRegisterVerify` — either the LINK branch
|
|
20
|
+
* (`{ success, message }`, bearer present, no session) or the SIGNUP branch (a
|
|
21
|
+
* full {@link LoginResult}, which carries a `sessionId` on its session arm).
|
|
22
|
+
*/
|
|
23
|
+
export type PasskeyRegisterVerifyResult = { success: true; message: string } | LoginResult;
|
|
24
|
+
|
|
25
|
+
/** Thrown when a passkey flow is attempted on a surface that cannot run WebAuthn. */
|
|
26
|
+
export const PASSKEY_UNSUPPORTED_MESSAGE =
|
|
27
|
+
'Passkeys are not available in this environment. Use another sign-in method.';
|
|
28
|
+
|
|
29
|
+
/** Project a session-arm login result onto the internal `commitSession` input. */
|
|
30
|
+
function toCommitInput(result: LoginSessionResult): CommitInput {
|
|
31
|
+
return {
|
|
32
|
+
sessionId: result.sessionId,
|
|
33
|
+
accessToken: result.accessToken,
|
|
34
|
+
deviceSecret: result.deviceSecret,
|
|
35
|
+
deviceId: result.deviceId,
|
|
36
|
+
expiresAt: result.expiresAt,
|
|
37
|
+
userId: result.user.id,
|
|
38
|
+
user: result.user,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Injected dependencies for {@link runPasskeyLogin}. */
|
|
43
|
+
export interface RunPasskeyLoginDeps {
|
|
44
|
+
isSupported: () => boolean;
|
|
45
|
+
getLoginOptions: (username?: string) => Promise<unknown>;
|
|
46
|
+
runCeremony: (optionsJSON: unknown) => Promise<unknown>;
|
|
47
|
+
loginVerify: (
|
|
48
|
+
response: unknown,
|
|
49
|
+
envelope: { deviceName?: string; deviceFingerprint?: string; deviceId?: string },
|
|
50
|
+
) => Promise<LoginResult>;
|
|
51
|
+
commit: (input: CommitInput) => Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* When present, scopes login options to that user's registered passkeys
|
|
54
|
+
* (username-first) — the path a NON-discoverable hardware key (e.g. a U2F
|
|
55
|
+
* security key) needs, since it can't be found by a usernameless ceremony.
|
|
56
|
+
* Omit for the discoverable / resident-credential path.
|
|
57
|
+
*/
|
|
58
|
+
username?: string;
|
|
59
|
+
deviceId?: string;
|
|
60
|
+
deviceName?: string;
|
|
61
|
+
deviceFingerprint?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Passkey SIGN-IN. With no `username` this is the usernameless
|
|
66
|
+
* (discoverable-credential) flow; with a `username` it is username-first —
|
|
67
|
+
* the server scopes `allowCredentials` to that user's passkeys so a
|
|
68
|
+
* non-discoverable hardware key (U2F/security key) can be selected. Either way:
|
|
69
|
+
* request login options, run the authentication ceremony, verify, then commit
|
|
70
|
+
* the session. A passkey assertion is itself the strong factor — sign-in always
|
|
71
|
+
* resolves to a completed session.
|
|
72
|
+
*/
|
|
73
|
+
export async function runPasskeyLogin(deps: RunPasskeyLoginDeps): Promise<void> {
|
|
74
|
+
if (!deps.isSupported()) {
|
|
75
|
+
throw new Error(PASSKEY_UNSUPPORTED_MESSAGE);
|
|
76
|
+
}
|
|
77
|
+
const options = await deps.getLoginOptions(deps.username);
|
|
78
|
+
const response = await deps.runCeremony(options);
|
|
79
|
+
const result = await deps.loginVerify(response, {
|
|
80
|
+
deviceName: deps.deviceName,
|
|
81
|
+
deviceFingerprint: deps.deviceFingerprint,
|
|
82
|
+
deviceId: deps.deviceId,
|
|
83
|
+
});
|
|
84
|
+
await deps.commit(toCommitInput(result));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Injected dependencies for {@link runPasskeyRegister}. */
|
|
88
|
+
export interface RunPasskeyRegisterDeps {
|
|
89
|
+
isSupported: () => boolean;
|
|
90
|
+
getRegisterOptions: (username: string) => Promise<unknown>;
|
|
91
|
+
runCeremony: (optionsJSON: unknown) => Promise<unknown>;
|
|
92
|
+
registerVerify: (
|
|
93
|
+
response: unknown,
|
|
94
|
+
envelope: { username: string; deviceName?: string },
|
|
95
|
+
) => Promise<PasskeyRegisterVerifyResult>;
|
|
96
|
+
commit: (input: CommitInput) => Promise<void>;
|
|
97
|
+
username: string;
|
|
98
|
+
deviceName?: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Passkey SIGNUP: create a brand-new account whose first auth method is a
|
|
103
|
+
* passkey. The verify signup branch mints a session (a {@link LoginSessionResult}
|
|
104
|
+
* carrying `sessionId`), which is committed exactly like a password signup.
|
|
105
|
+
*/
|
|
106
|
+
export async function runPasskeyRegister(deps: RunPasskeyRegisterDeps): Promise<void> {
|
|
107
|
+
if (!deps.isSupported()) {
|
|
108
|
+
throw new Error(PASSKEY_UNSUPPORTED_MESSAGE);
|
|
109
|
+
}
|
|
110
|
+
const options = await deps.getRegisterOptions(deps.username);
|
|
111
|
+
const response = await deps.runCeremony(options);
|
|
112
|
+
const result = await deps.registerVerify(response, {
|
|
113
|
+
username: deps.username,
|
|
114
|
+
deviceName: deps.deviceName,
|
|
115
|
+
});
|
|
116
|
+
// Only the signup session arm carries `sessionId`; the link branch
|
|
117
|
+
// (`{ success, message }`) does not.
|
|
118
|
+
if (!('sessionId' in result)) {
|
|
119
|
+
throw new Error('Passkey registration did not establish a session.');
|
|
120
|
+
}
|
|
121
|
+
await deps.commit(toCommitInput(result));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Injected dependencies for {@link runPasskeyAdd}. */
|
|
125
|
+
export interface RunPasskeyAddDeps {
|
|
126
|
+
isSupported: () => boolean;
|
|
127
|
+
getRegisterOptions: () => Promise<unknown>;
|
|
128
|
+
runCeremony: (optionsJSON: unknown) => Promise<unknown>;
|
|
129
|
+
registerVerify: (
|
|
130
|
+
response: unknown,
|
|
131
|
+
envelope: { deviceName?: string },
|
|
132
|
+
) => Promise<PasskeyRegisterVerifyResult>;
|
|
133
|
+
onLinked: () => void;
|
|
134
|
+
deviceName?: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* ADD a passkey to the already-signed-in account (bearer present). The verify
|
|
139
|
+
* link branch returns `{ success, message }` with NO session — so this never
|
|
140
|
+
* commits a session; it just fires `onLinked` (which invalidates the
|
|
141
|
+
* auth-methods query). A session arm here would be a server contract violation.
|
|
142
|
+
*/
|
|
143
|
+
export async function runPasskeyAdd(deps: RunPasskeyAddDeps): Promise<void> {
|
|
144
|
+
if (!deps.isSupported()) {
|
|
145
|
+
throw new Error(PASSKEY_UNSUPPORTED_MESSAGE);
|
|
146
|
+
}
|
|
147
|
+
const options = await deps.getRegisterOptions();
|
|
148
|
+
const response = await deps.runCeremony(options);
|
|
149
|
+
const result = await deps.registerVerify(response, { deviceName: deps.deviceName });
|
|
150
|
+
if ('sessionId' in result) {
|
|
151
|
+
throw new Error('addPasskey unexpectedly minted a new session instead of linking.');
|
|
152
|
+
}
|
|
153
|
+
deps.onLinked();
|
|
154
|
+
}
|
|
@@ -71,6 +71,12 @@ export const queryKeys = {
|
|
|
71
71
|
[...queryKeys.security.all, 'infinite', limit, eventType] as const,
|
|
72
72
|
},
|
|
73
73
|
|
|
74
|
+
// Linked authentication methods (passwords, identity keys, passkeys, social)
|
|
75
|
+
authMethods: {
|
|
76
|
+
all: ['authMethods'] as const,
|
|
77
|
+
list: (userId?: string) => [...queryKeys.authMethods.all, 'list', userId || 'current'] as const,
|
|
78
|
+
},
|
|
79
|
+
|
|
74
80
|
// Storage usage queries
|
|
75
81
|
storage: {
|
|
76
82
|
all: ['storage'] as const,
|
|
@@ -159,6 +165,14 @@ export const invalidateStorageQueries = (queryClient: QueryClient): void => {
|
|
|
159
165
|
queryClient.invalidateQueries({ queryKey: queryKeys.storage.all });
|
|
160
166
|
};
|
|
161
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Helper to invalidate the user's linked auth-methods list (call after linking
|
|
170
|
+
* or removing a passkey / password / identity key).
|
|
171
|
+
*/
|
|
172
|
+
export const invalidateAuthMethodsQueries = (queryClient: QueryClient): void => {
|
|
173
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.authMethods.all });
|
|
174
|
+
};
|
|
175
|
+
|
|
162
176
|
/**
|
|
163
177
|
* Helper to invalidate all payments / wallet / subscription queries
|
|
164
178
|
*/
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
import type { AuthMethodEntry, AuthMethodsResponse } from '@oxyhq/contracts';
|
|
4
|
+
import { queryKeys } from './queryKeys';
|
|
5
|
+
import { useOxy } from '../../context/OxyContext';
|
|
6
|
+
|
|
7
|
+
/** Stable empty list so the derived selectors keep a stable reference while loading. */
|
|
8
|
+
const EMPTY_METHODS: readonly AuthMethodEntry[] = Object.freeze([]);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The current account's linked authentication methods (`GET /auth/methods`),
|
|
12
|
+
* plus convenience projections. Backs the security / account surfaces that let a
|
|
13
|
+
* user see and manage their passwords, identity key, social logins, and passkeys.
|
|
14
|
+
*
|
|
15
|
+
* `passkeys` is the `type === 'webauthn'` subset — one entry per registered
|
|
16
|
+
* credential. Invalidate via `queryKeys.authMethods.all` after linking a passkey
|
|
17
|
+
* (`useOxy().addPasskey()` does this) or removing one.
|
|
18
|
+
*/
|
|
19
|
+
export const useAuthMethods = (options?: { enabled?: boolean }) => {
|
|
20
|
+
const { oxyServices, activeSessionId } = useOxy();
|
|
21
|
+
|
|
22
|
+
const query = useQuery<AuthMethodsResponse>({
|
|
23
|
+
queryKey: queryKeys.authMethods.list(),
|
|
24
|
+
queryFn: () => oxyServices.listAuthMethods(),
|
|
25
|
+
enabled: options?.enabled !== false && !!activeSessionId,
|
|
26
|
+
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
27
|
+
gcTime: 10 * 60 * 1000, // 10 minutes
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const methods = query.data?.methods ?? EMPTY_METHODS;
|
|
31
|
+
const passkeys = useMemo(
|
|
32
|
+
() => methods.filter((method) => method.type === 'webauthn'),
|
|
33
|
+
[methods],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...query,
|
|
38
|
+
/** Every linked auth method. Empty while loading. */
|
|
39
|
+
methods,
|
|
40
|
+
/** The registered passkeys (a `type === 'webauthn'` subset of `methods`). */
|
|
41
|
+
passkeys,
|
|
42
|
+
/** The account's DID, or `null` while loading. */
|
|
43
|
+
did: query.data?.did ?? null,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -62,6 +62,14 @@ export interface OxyProviderProps {
|
|
|
62
62
|
baseURL?: string;
|
|
63
63
|
authWebUrl?: string;
|
|
64
64
|
authRedirectUri?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Authorize endpoint override for silent cross-origin session restore
|
|
67
|
+
* (web cross-app SSO on cold boot). Defaults to the production Oxy IdP
|
|
68
|
+
* (`https://auth.oxy.so/authorize`) when unset. Set this from an env var
|
|
69
|
+
* (e.g. Vite `VITE_OXY_AUTHORIZE_URL`, Expo `EXPO_PUBLIC_OXY_AUTHORIZE_URL`)
|
|
70
|
+
* so a local/staging deployment targets its own IdP instead of production.
|
|
71
|
+
*/
|
|
72
|
+
authorizeBaseUrl?: string;
|
|
65
73
|
queryClient?: QueryClient;
|
|
66
74
|
/** Sync device credentials to auth.oxy.so after interactive sign-in. @default true */
|
|
67
75
|
hubSync?: boolean;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { OxyServices } from '@oxyhq/core';
|
|
2
|
+
|
|
3
|
+
// Spy on the platform redirect so no real navigation happens and we can assert
|
|
4
|
+
// the authorize URL the silent-restore flow hands to the browser.
|
|
5
|
+
jest.mock('../../components/oauthNavigation', () => ({
|
|
6
|
+
redirectToAuthorize: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
// jsdom's `location` is non-configurable, so the origin the code reads cannot be
|
|
10
|
+
// reassigned per-test. Instead, drive the ORIGIN-CLASSIFICATION predicates
|
|
11
|
+
// (whose real behaviour is covered by core's officialOrigins.test.ts) and keep
|
|
12
|
+
// every other core helper real (PKCE, authorize-URL builder, handshake store).
|
|
13
|
+
jest.mock('@oxyhq/core', () => {
|
|
14
|
+
const actual = jest.requireActual('@oxyhq/core');
|
|
15
|
+
return {
|
|
16
|
+
__esModule: true,
|
|
17
|
+
...actual,
|
|
18
|
+
isLoopbackOrigin: jest.fn(),
|
|
19
|
+
isOfficialWebOrigin: jest.fn(),
|
|
20
|
+
isIdpHubOrigin: jest.fn(),
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
isLoopbackOrigin,
|
|
26
|
+
isOfficialWebOrigin,
|
|
27
|
+
isIdpHubOrigin,
|
|
28
|
+
} from '@oxyhq/core';
|
|
29
|
+
import { redirectToAuthorize } from '../../components/oauthNavigation';
|
|
30
|
+
import {
|
|
31
|
+
isSilentRestoreEligibleOrigin,
|
|
32
|
+
maybeStartSilentOAuthRestore,
|
|
33
|
+
clearCrossOriginRestoreGuards,
|
|
34
|
+
} from '../crossOriginRestore';
|
|
35
|
+
|
|
36
|
+
const mockRedirect = redirectToAuthorize as jest.Mock;
|
|
37
|
+
const mockIsLoopback = isLoopbackOrigin as jest.Mock;
|
|
38
|
+
const mockIsOfficial = isOfficialWebOrigin as jest.Mock;
|
|
39
|
+
const mockIsIdpHub = isIdpHubOrigin as jest.Mock;
|
|
40
|
+
|
|
41
|
+
const OXY_SERVICES_STUB = {} as OxyServices;
|
|
42
|
+
|
|
43
|
+
/** Default to an eligible official origin; individual tests narrow this. */
|
|
44
|
+
function makeOriginEligible(): void {
|
|
45
|
+
mockIsLoopback.mockReturnValue(false);
|
|
46
|
+
mockIsIdpHub.mockReturnValue(false);
|
|
47
|
+
mockIsOfficial.mockReturnValue(true);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('crossOriginRestore', () => {
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
mockRedirect.mockClear();
|
|
53
|
+
mockIsLoopback.mockReset();
|
|
54
|
+
mockIsOfficial.mockReset();
|
|
55
|
+
mockIsIdpHub.mockReset();
|
|
56
|
+
globalThis.sessionStorage?.clear();
|
|
57
|
+
clearCrossOriginRestoreGuards();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('isSilentRestoreEligibleOrigin', () => {
|
|
61
|
+
it('rejects loopback / local-dev origins', () => {
|
|
62
|
+
mockIsLoopback.mockReturnValue(true);
|
|
63
|
+
mockIsIdpHub.mockReturnValue(false);
|
|
64
|
+
mockIsOfficial.mockReturnValue(true);
|
|
65
|
+
expect(isSilentRestoreEligibleOrigin('http://localhost:3000')).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('rejects the central IdP hub origin (no self-hop)', () => {
|
|
69
|
+
mockIsLoopback.mockReturnValue(false);
|
|
70
|
+
mockIsIdpHub.mockReturnValue(true);
|
|
71
|
+
mockIsOfficial.mockReturnValue(true);
|
|
72
|
+
expect(isSilentRestoreEligibleOrigin('https://auth.oxy.so')).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('rejects non-official origins', () => {
|
|
76
|
+
mockIsLoopback.mockReturnValue(false);
|
|
77
|
+
mockIsIdpHub.mockReturnValue(false);
|
|
78
|
+
mockIsOfficial.mockReturnValue(false);
|
|
79
|
+
expect(isSilentRestoreEligibleOrigin('https://evil.example')).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('accepts official, non-loopback, non-IdP origins', () => {
|
|
83
|
+
makeOriginEligible();
|
|
84
|
+
expect(isSilentRestoreEligibleOrigin('https://accounts.oxy.so')).toBe(true);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('maybeStartSilentOAuthRestore', () => {
|
|
89
|
+
it('is SKIPPED on a loopback origin (no redirect)', async () => {
|
|
90
|
+
mockIsLoopback.mockReturnValue(true);
|
|
91
|
+
mockIsIdpHub.mockReturnValue(false);
|
|
92
|
+
mockIsOfficial.mockReturnValue(true);
|
|
93
|
+
const redirected = await maybeStartSilentOAuthRestore({
|
|
94
|
+
oxyServices: OXY_SERVICES_STUB,
|
|
95
|
+
clientId: 'oxy_dk_test',
|
|
96
|
+
});
|
|
97
|
+
expect(redirected).toBe(false);
|
|
98
|
+
expect(mockRedirect).not.toHaveBeenCalled();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('is SKIPPED on a non-official origin (no redirect)', async () => {
|
|
102
|
+
mockIsLoopback.mockReturnValue(false);
|
|
103
|
+
mockIsIdpHub.mockReturnValue(false);
|
|
104
|
+
mockIsOfficial.mockReturnValue(false);
|
|
105
|
+
const redirected = await maybeStartSilentOAuthRestore({
|
|
106
|
+
oxyServices: OXY_SERVICES_STUB,
|
|
107
|
+
clientId: 'oxy_dk_test',
|
|
108
|
+
});
|
|
109
|
+
expect(redirected).toBe(false);
|
|
110
|
+
expect(mockRedirect).not.toHaveBeenCalled();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('redirects to the PROD IdP by default on an eligible origin', async () => {
|
|
114
|
+
makeOriginEligible();
|
|
115
|
+
const redirected = await maybeStartSilentOAuthRestore({
|
|
116
|
+
oxyServices: OXY_SERVICES_STUB,
|
|
117
|
+
clientId: 'oxy_dk_test',
|
|
118
|
+
});
|
|
119
|
+
expect(redirected).toBe(true);
|
|
120
|
+
expect(mockRedirect).toHaveBeenCalledTimes(1);
|
|
121
|
+
const url = mockRedirect.mock.calls[0][0] as string;
|
|
122
|
+
expect(url.startsWith('https://auth.oxy.so/authorize?')).toBe(true);
|
|
123
|
+
const params = new URL(url).searchParams;
|
|
124
|
+
expect(params.get('client_id')).toBe('oxy_dk_test');
|
|
125
|
+
expect(params.get('prompt')).toBe('none');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('honors an authorizeBaseUrl override (self-hosted / staging IdP)', async () => {
|
|
129
|
+
makeOriginEligible();
|
|
130
|
+
const redirected = await maybeStartSilentOAuthRestore({
|
|
131
|
+
oxyServices: OXY_SERVICES_STUB,
|
|
132
|
+
clientId: 'oxy_dk_test',
|
|
133
|
+
authorizeBaseUrl: 'https://auth.staging.oxy.so/authorize',
|
|
134
|
+
});
|
|
135
|
+
expect(redirected).toBe(true);
|
|
136
|
+
const url = mockRedirect.mock.calls[0][0] as string;
|
|
137
|
+
expect(url.startsWith('https://auth.staging.oxy.so/authorize?')).toBe(true);
|
|
138
|
+
const params = new URL(url).searchParams;
|
|
139
|
+
expect(params.get('client_id')).toBe('oxy_dk_test');
|
|
140
|
+
expect(params.get('prompt')).toBe('none');
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
@@ -3,6 +3,9 @@ import {
|
|
|
3
3
|
buildOAuthAuthorizeUrl,
|
|
4
4
|
generateOAuthState,
|
|
5
5
|
generatePkcePair,
|
|
6
|
+
isIdpHubOrigin,
|
|
7
|
+
isLoopbackOrigin,
|
|
8
|
+
isOfficialWebOrigin,
|
|
6
9
|
OXY_CROSS_ORIGIN_RESTORE_ATTEMPTED_KEY,
|
|
7
10
|
OXY_SILENT_OAUTH_ATTEMPTED_KEY,
|
|
8
11
|
persistOAuthHandshake,
|
|
@@ -43,11 +46,35 @@ export function clearCrossOriginRestoreGuards(): void {
|
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Whether cold boot should attempt silent cross-origin OAuth restore for the
|
|
51
|
+
* given web origin.
|
|
52
|
+
*
|
|
53
|
+
* Mirrors the hub-sync WRITE gate (`syncHubAfterSignIn`): only OFFICIAL Oxy web
|
|
54
|
+
* origins participate in cross-app SSO — a random third-party / preview origin
|
|
55
|
+
* must never have its tab bounced to the IdP. Additionally, loopback / local-dev
|
|
56
|
+
* origins are EXCLUDED here even though {@link isOfficialWebOrigin} treats them
|
|
57
|
+
* as official: a developer's local app must never be redirected to a hosted IdP
|
|
58
|
+
* on cold boot (it signs in through the in-app dialog instead). The central IdP
|
|
59
|
+
* hub's own origin is excluded to avoid a wasteful self-hop.
|
|
60
|
+
*/
|
|
61
|
+
export function isSilentRestoreEligibleOrigin(origin: string): boolean {
|
|
62
|
+
if (isLoopbackOrigin(origin)) return false;
|
|
63
|
+
if (isIdpHubOrigin()) return false;
|
|
64
|
+
return isOfficialWebOrigin(origin);
|
|
65
|
+
}
|
|
66
|
+
|
|
46
67
|
export interface SilentOAuthRestoreOptions {
|
|
47
68
|
oxyServices: OxyServices;
|
|
48
69
|
clientId: string;
|
|
49
70
|
redirectUri?: string;
|
|
50
71
|
scope?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Authorize endpoint override (env-configurable per deployment). Defaults to
|
|
74
|
+
* the production Oxy IdP when unset, so a local/staging app points silent
|
|
75
|
+
* restore at its OWN IdP instead of production `auth.oxy.so`.
|
|
76
|
+
*/
|
|
77
|
+
authorizeBaseUrl?: string;
|
|
51
78
|
}
|
|
52
79
|
|
|
53
80
|
/**
|
|
@@ -62,6 +89,12 @@ export async function maybeStartSilentOAuthRestore(
|
|
|
62
89
|
const location = (globalThis as { location?: Location }).location;
|
|
63
90
|
if (!location) return false;
|
|
64
91
|
|
|
92
|
+
// Defense-in-depth: never bounce a loopback / non-official / IdP-hub origin to
|
|
93
|
+
// a hosted authorize endpoint (the caller gates on this too).
|
|
94
|
+
if (!isSilentRestoreEligibleOrigin(location.origin)) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
|
|
65
98
|
if (isCrossOriginRestoreBlocked()) {
|
|
66
99
|
return false;
|
|
67
100
|
}
|
|
@@ -83,6 +116,7 @@ export async function maybeStartSilentOAuthRestore(
|
|
|
83
116
|
);
|
|
84
117
|
|
|
85
118
|
const authorizeUrl = buildOAuthAuthorizeUrl({
|
|
119
|
+
authorizeBaseUrl: opts.authorizeBaseUrl,
|
|
86
120
|
clientId: opts.clientId,
|
|
87
121
|
redirectUri,
|
|
88
122
|
state,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passkey / WebAuthn ceremony client — NATIVE implementation.
|
|
3
|
+
*
|
|
4
|
+
* React Native has no browser WebAuthn API, and Oxy's native passkey story is
|
|
5
|
+
* Commons (shared-keychain / QR handoff), NOT `navigator.credentials`. So this
|
|
6
|
+
* variant imports NOTHING browser-specific and mirrors the clean default:
|
|
7
|
+
* unsupported, and the ceremony helpers throw if a caller skipped the gate.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const WEBAUTHN_WEB_ONLY_MESSAGE =
|
|
11
|
+
'WebAuthn is web-only; native uses Commons. Passkeys are not available on this platform.';
|
|
12
|
+
|
|
13
|
+
/** Always `false` on native — there is no browser WebAuthn API. */
|
|
14
|
+
export function isPasskeySupported(): boolean {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Not available on native — throws. Guard with {@link isPasskeySupported} first. */
|
|
19
|
+
export async function runRegistrationCeremony(_optionsJSON: unknown): Promise<unknown> {
|
|
20
|
+
throw new Error(WEBAUTHN_WEB_ONLY_MESSAGE);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Not available on native — throws. Guard with {@link isPasskeySupported} first. */
|
|
24
|
+
export async function runAuthenticationCeremony(_optionsJSON: unknown): Promise<unknown> {
|
|
25
|
+
throw new Error(WEBAUTHN_WEB_ONLY_MESSAGE);
|
|
26
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passkey / WebAuthn ceremony client — clean default (non-web) implementation.
|
|
3
|
+
*
|
|
4
|
+
* This is the base module TypeScript resolves for TYPES and any bundler that
|
|
5
|
+
* does not pick a platform variant. It intentionally imports NOTHING browser-
|
|
6
|
+
* specific (no `@simplewebauthn/browser`) so it stays safe for Metro, native
|
|
7
|
+
* builds, and SSR. The real ceremony lives in `passkeyClient.web.ts`; native
|
|
8
|
+
* passkeys are Commons' job, so there is no WebAuthn ceremony here.
|
|
9
|
+
*
|
|
10
|
+
* `isPasskeySupported()` returns `false` (no relying-party origin / no browser
|
|
11
|
+
* WebAuthn API), and the ceremony helpers throw a clear error so a caller that
|
|
12
|
+
* skipped the support gate fails loudly instead of silently.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const WEBAUTHN_WEB_ONLY_MESSAGE =
|
|
16
|
+
'WebAuthn is web-only; native uses Commons. Passkeys are not available on this platform.';
|
|
17
|
+
|
|
18
|
+
/** Always `false` off the web — there is no relying-party origin or WebAuthn API. */
|
|
19
|
+
export function isPasskeySupported(): boolean {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Not available off the web — throws. Guard with {@link isPasskeySupported} first. */
|
|
24
|
+
export async function runRegistrationCeremony(_optionsJSON: unknown): Promise<unknown> {
|
|
25
|
+
throw new Error(WEBAUTHN_WEB_ONLY_MESSAGE);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Not available off the web — throws. Guard with {@link isPasskeySupported} first. */
|
|
29
|
+
export async function runAuthenticationCeremony(_optionsJSON: unknown): Promise<unknown> {
|
|
30
|
+
throw new Error(WEBAUTHN_WEB_ONLY_MESSAGE);
|
|
31
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passkey / WebAuthn ceremony client — WEB implementation.
|
|
3
|
+
*
|
|
4
|
+
* The browser half of the passkey flow: it drives `navigator.credentials`
|
|
5
|
+
* through `@simplewebauthn/browser`, turning the OPAQUE options the server
|
|
6
|
+
* emitted (`OxyServices.webauthn{Register,Login}Options`) into the opaque
|
|
7
|
+
* response the matching `verify` endpoint consumes. Oxy never owns those wire
|
|
8
|
+
* shapes — `@simplewebauthn/browser` does — so options flow in as `unknown` and
|
|
9
|
+
* the single cast at this boundary hands them to the library's own types.
|
|
10
|
+
*
|
|
11
|
+
* This file is selected ONLY on web (react-native-web / Vite RNW): the sibling
|
|
12
|
+
* `passkeyClient.native.ts` + the clean default `passkeyClient.ts` deliberately
|
|
13
|
+
* do NOT import `@simplewebauthn/browser` (a browser-only dependency), per the
|
|
14
|
+
* platform-split rule. Native passkeys are Commons' job — there is no WebAuthn
|
|
15
|
+
* ceremony off the web.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
startRegistration,
|
|
20
|
+
startAuthentication,
|
|
21
|
+
type PublicKeyCredentialCreationOptionsJSON,
|
|
22
|
+
type PublicKeyCredentialRequestOptionsJSON,
|
|
23
|
+
type RegistrationResponseJSON,
|
|
24
|
+
type AuthenticationResponseJSON,
|
|
25
|
+
} from '@simplewebauthn/browser';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* True iff this browser can run a WebAuthn ceremony (exposes the
|
|
29
|
+
* `PublicKeyCredential` global). Gate all passkey UI/entrypoints on this so an
|
|
30
|
+
* unsupported browser fails loudly rather than throwing mid-ceremony.
|
|
31
|
+
*/
|
|
32
|
+
export function isPasskeySupported(): boolean {
|
|
33
|
+
return typeof window !== 'undefined' && typeof window.PublicKeyCredential !== 'undefined';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Run the WebAuthn REGISTRATION ceremony (`navigator.credentials.create`) from
|
|
38
|
+
* the server's opaque creation options, returning the opaque attestation
|
|
39
|
+
* response for `OxyServices.webauthnRegisterVerify`.
|
|
40
|
+
*/
|
|
41
|
+
export async function runRegistrationCeremony(
|
|
42
|
+
optionsJSON: unknown,
|
|
43
|
+
): Promise<RegistrationResponseJSON> {
|
|
44
|
+
return startRegistration({ optionsJSON: optionsJSON as PublicKeyCredentialCreationOptionsJSON });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Run the WebAuthn AUTHENTICATION ceremony (`navigator.credentials.get`) from
|
|
49
|
+
* the server's opaque request options, returning the opaque assertion response
|
|
50
|
+
* for `OxyServices.webauthnLoginVerify`.
|
|
51
|
+
*/
|
|
52
|
+
export async function runAuthenticationCeremony(
|
|
53
|
+
optionsJSON: unknown,
|
|
54
|
+
): Promise<AuthenticationResponseJSON> {
|
|
55
|
+
return startAuthentication({ optionsJSON: optionsJSON as PublicKeyCredentialRequestOptionsJSON });
|
|
56
|
+
}
|