@passflow/core 0.24.0 → 0.26.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 +35 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +130 -7
- package/dist/index.d.ts +130 -7
- package/dist/index.mjs +783 -660
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1004,6 +1004,7 @@ export declare enum PassflowEndpointPaths {
|
|
|
1004
1004
|
signin = "/auth/login",
|
|
1005
1005
|
signup = "/auth/register",
|
|
1006
1006
|
pkceExchange = "/auth/pkce_exchange",
|
|
1007
|
+
redirectCheck = "/auth/redirect/check",
|
|
1007
1008
|
signInWithProvider = "/auth/federated/start/",
|
|
1008
1009
|
passwordless = "/auth/passwordless/start",
|
|
1009
1010
|
passwordlessComplete = "/auth/passwordless/complete",
|
|
@@ -1042,6 +1043,10 @@ export declare enum PassflowEndpointPaths {
|
|
|
1042
1043
|
twoFactorRecovery = "/auth/2fa/recovery",
|
|
1043
1044
|
twoFactorRegenerateCodes = "/user/2fa/recovery-codes/regenerate",
|
|
1044
1045
|
twoFactorSetupMagicLink = "/auth/2fa-setup", // :token param appended in API call
|
|
1046
|
+
twoFactorEnrollment = "/auth/2fa/enrollment",
|
|
1047
|
+
twoFactorEnrollmentEmailLink = "/auth/2fa/enrollment/email-link",
|
|
1048
|
+
twoFactorEnrollmentBegin = "/auth/2fa/setup/begin",
|
|
1049
|
+
twoFactorEnrollmentConfirm = "/auth/2fa/setup/confirm",
|
|
1045
1050
|
TwoFactorMethodsAvailable = "/v2/user/2fa/methods/available",
|
|
1046
1051
|
TwoFactorMethodsRegistered = "/v2/user/2fa/methods",
|
|
1047
1052
|
TwoFactorSetupStart = "/v2/user/2fa/setup/start",
|
|
@@ -1817,13 +1822,33 @@ export type TwoFactorStatusResponse = {
|
|
|
1817
1822
|
};
|
|
1818
1823
|
export type TwoFactorSetupResponse = {
|
|
1819
1824
|
secret: string;
|
|
1825
|
+
/** Base64-encoded PNG of the QR code. Empty when the server sent no image: use `qr_code_url`. */
|
|
1820
1826
|
qr_code: string;
|
|
1827
|
+
/** The `otpauth://` URL the QR code holds. */
|
|
1828
|
+
qr_code_url?: string;
|
|
1821
1829
|
totp_digits?: 6 | 8;
|
|
1822
1830
|
};
|
|
1823
1831
|
export type TwoFactorConfirmResponse = {
|
|
1824
1832
|
success: true;
|
|
1833
|
+
enabled?: boolean;
|
|
1825
1834
|
recovery_codes: string[];
|
|
1826
1835
|
};
|
|
1836
|
+
/**
|
|
1837
|
+
* What a sign-in waiting on its second factor can do next, decided by the server:
|
|
1838
|
+
* - `verify`: ask for a code; the user has a factor the app accepts.
|
|
1839
|
+
* - `email_link`: no factor yet and a validated email: send the setup link, then the user signs in again.
|
|
1840
|
+
* - `direct`: no factor and no validated email: enrol here, then finish with the code.
|
|
1841
|
+
* - `unavailable`: the app offers no way to enrol this user: contact the administrator.
|
|
1842
|
+
*/
|
|
1843
|
+
export type TwoFactorEnrollment = 'verify' | 'email_link' | 'direct' | 'unavailable';
|
|
1844
|
+
/** GET /auth/2fa/enrollment */
|
|
1845
|
+
export type TwoFactorEnrollmentResponse = {
|
|
1846
|
+
enrollment: TwoFactorEnrollment;
|
|
1847
|
+
};
|
|
1848
|
+
/** POST /auth/2fa/enrollment/email-link */
|
|
1849
|
+
export type TwoFactorSetupLinkResponse = {
|
|
1850
|
+
email_sent: boolean;
|
|
1851
|
+
};
|
|
1827
1852
|
export type TwoFactorVerifyResponse = Tokens & {
|
|
1828
1853
|
success: true;
|
|
1829
1854
|
/** On a PKCE app; `TwoFactorService` redeems it, so its callers never see one. */
|
|
@@ -1872,7 +1897,7 @@ export type TwoFactorRegenerateResponse = {
|
|
|
1872
1897
|
/**
|
|
1873
1898
|
* Two-Factor magic link error codes
|
|
1874
1899
|
*/
|
|
1875
|
-
export type TwoFactorSetupMagicLinkErrorCode = 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'RATE_LIMITED' | 'SERVER_ERROR';
|
|
1900
|
+
export type TwoFactorSetupMagicLinkErrorCode = 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'ALREADY_USED' | 'RATE_LIMITED' | 'SERVER_ERROR';
|
|
1876
1901
|
/**
|
|
1877
1902
|
* Two-Factor magic link error details
|
|
1878
1903
|
*/
|
|
@@ -2140,6 +2165,8 @@ export declare class AuthAPI {
|
|
|
2140
2165
|
passwordlessStatus(payload: PassflowPasswordlessStatusPayload, options?: {
|
|
2141
2166
|
signal?: AbortSignal;
|
|
2142
2167
|
}): Promise<PassflowPasswordlessStatusResponse>;
|
|
2168
|
+
/** Asks the server whether this app may redirect to `url`, and for the address to use. */
|
|
2169
|
+
checkRedirectUrl(url: string): Promise<string>;
|
|
2143
2170
|
/** Reads what the approving device shows. It changes nothing on the server. */
|
|
2144
2171
|
passwordlessApprovalInfo(payload: PassflowPasswordlessApprovalInfoPayload): Promise<PasswordlessApprovalInfo>;
|
|
2145
2172
|
/**
|
|
@@ -2475,20 +2502,46 @@ export declare class TwoFactorApiClient {
|
|
|
2475
2502
|
/**
|
|
2476
2503
|
* Get current 2FA enrollment status
|
|
2477
2504
|
* GET /user/2fa/status
|
|
2505
|
+
*
|
|
2506
|
+
* `setupSessionToken` is a setup link's session; without it the stored session is used.
|
|
2478
2507
|
*/
|
|
2479
|
-
getStatus(): Promise<TwoFactorStatusResponse>;
|
|
2508
|
+
getStatus(setupSessionToken?: string): Promise<TwoFactorStatusResponse>;
|
|
2480
2509
|
/**
|
|
2481
2510
|
* Begin 2FA setup process
|
|
2482
2511
|
* POST /user/2fa/setup/begin
|
|
2483
2512
|
* Returns secret and QR code for authenticator app
|
|
2513
|
+
*
|
|
2514
|
+
* `setupSessionToken` is a setup link's session; without it the stored session is used.
|
|
2484
2515
|
*/
|
|
2485
|
-
beginSetup(): Promise<TwoFactorSetupResponse>;
|
|
2516
|
+
beginSetup(setupSessionToken?: string): Promise<TwoFactorSetupResponse>;
|
|
2486
2517
|
/**
|
|
2487
2518
|
* Confirm 2FA setup with TOTP code
|
|
2488
2519
|
* POST /user/2fa/setup/confirm
|
|
2489
2520
|
* Returns recovery codes on success
|
|
2521
|
+
*
|
|
2522
|
+
* `setupSessionToken` is a setup link's session; without it the stored session is used.
|
|
2523
|
+
*/
|
|
2524
|
+
confirmSetup(payload: TwoFactorConfirmRequest, setupSessionToken?: string): Promise<TwoFactorConfirmResponse>;
|
|
2525
|
+
/**
|
|
2526
|
+
* What a sign-in waiting on its second factor can do next
|
|
2527
|
+
* GET /auth/2fa/enrollment
|
|
2490
2528
|
*/
|
|
2491
|
-
|
|
2529
|
+
getEnrollment(tfaToken: string): Promise<TwoFactorEnrollment>;
|
|
2530
|
+
/**
|
|
2531
|
+
* Email the user a link to set up 2FA
|
|
2532
|
+
* POST /auth/2fa/enrollment/email-link
|
|
2533
|
+
*/
|
|
2534
|
+
sendSetupLink(tfaToken: string): Promise<TwoFactorSetupLinkResponse>;
|
|
2535
|
+
/**
|
|
2536
|
+
* Begin 2FA setup on the sign-in itself, for a user with no validated email
|
|
2537
|
+
* POST /auth/2fa/setup/begin
|
|
2538
|
+
*/
|
|
2539
|
+
beginEnrollment(tfaToken: string): Promise<TwoFactorSetupResponse>;
|
|
2540
|
+
/**
|
|
2541
|
+
* Confirm 2FA setup on the sign-in itself; `verify` with the same code then finishes it
|
|
2542
|
+
* POST /auth/2fa/setup/confirm
|
|
2543
|
+
*/
|
|
2544
|
+
confirmEnrollment(tfaToken: string, payload: TwoFactorConfirmRequest): Promise<TwoFactorConfirmResponse>;
|
|
2492
2545
|
/**
|
|
2493
2546
|
* Verify TOTP code during login
|
|
2494
2547
|
* POST /auth/2fa/verify
|
|
@@ -3393,7 +3446,7 @@ export declare enum PassflowEvent {
|
|
|
3393
3446
|
* The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
|
|
3394
3447
|
* emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
|
|
3395
3448
|
*/
|
|
3396
|
-
type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'passwordless.wait' | 'passwordless.approval' | 'password-reset.send' | 'password-reset.complete' | 'email-verification.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | 'federated.redirect' | 'auth-redirect.url' | 'auth-redirect' | 'auth.is-authenticated' | 'session.check' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | 'settings.app' | 'settings.all' | 'settings.password-policy' | 'settings.passkey' | 'passkey.list' | 'passkey.rename' | 'passkey.delete' | 'passkey.add' | 'tenant.create' | 'invitation.join' | 'invitation.request-link' | 'invitation.list' | 'invitation.delete' | 'invitation.resend' | 'invitation.get-link' | '2fa.status' | '2fa.setup.begin' | '2fa.setup.confirm' | '2fa.verify' | '2fa.recovery.use' | '2fa.disable' | '2fa.recovery.regenerate' | '2fa.methods.available' | '2fa.methods.registered' | '2fa.method.setup.start' | '2fa.method.setup.complete' | '2fa.method.remove' | '2fa.challenge.request' | '2fa.challenge.verify' | '2fa.method.switch' | '2fa.trusted-devices.list' | '2fa.trusted-devices.revoke';
|
|
3449
|
+
type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'passwordless.wait' | 'passwordless.approval' | 'password-reset.send' | 'password-reset.complete' | 'email-verification.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | 'federated.redirect' | 'auth-redirect.url' | 'auth-redirect' | 'redirect.check' | 'auth.is-authenticated' | 'session.check' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | 'settings.app' | 'settings.all' | 'settings.password-policy' | 'settings.passkey' | 'passkey.list' | 'passkey.rename' | 'passkey.delete' | 'passkey.add' | 'tenant.create' | 'invitation.join' | 'invitation.request-link' | 'invitation.list' | 'invitation.delete' | 'invitation.resend' | 'invitation.get-link' | '2fa.status' | '2fa.setup.begin' | '2fa.setup.confirm' | '2fa.enrollment.read' | '2fa.enrollment.setup-link' | '2fa.verify' | '2fa.recovery.use' | '2fa.disable' | '2fa.recovery.regenerate' | '2fa.methods.available' | '2fa.methods.registered' | '2fa.method.setup.start' | '2fa.method.setup.complete' | '2fa.method.remove' | '2fa.challenge.request' | '2fa.challenge.verify' | '2fa.method.switch' | '2fa.trusted-devices.list' | '2fa.trusted-devices.revoke';
|
|
3397
3450
|
/**
|
|
3398
3451
|
* Error payload interface for structured error information
|
|
3399
3452
|
*/
|
|
@@ -3514,7 +3567,7 @@ type PassflowEventPayload = {
|
|
|
3514
3567
|
};
|
|
3515
3568
|
[PassflowEvent.TwoFactorSetupMagicLinkFailed]: {
|
|
3516
3569
|
error: {
|
|
3517
|
-
code: 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'RATE_LIMITED' | 'SERVER_ERROR';
|
|
3570
|
+
code: 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'ALREADY_USED' | 'RATE_LIMITED' | 'SERVER_ERROR';
|
|
3518
3571
|
message: string;
|
|
3519
3572
|
retryAfter?: number;
|
|
3520
3573
|
};
|
|
@@ -3820,6 +3873,7 @@ export declare class AuthService {
|
|
|
3820
3873
|
expiresAt: number;
|
|
3821
3874
|
} | undefined;
|
|
3822
3875
|
/** What the approving device shows about a waiting sign-in. It changes nothing on the server. */
|
|
3876
|
+
checkRedirectUrl(url: string): Promise<string>;
|
|
3823
3877
|
getPasswordlessApproval(challengeId: string): Promise<PasswordlessApprovalInfo>;
|
|
3824
3878
|
/** Approves or denies a waiting sign-in. `matchCode` is the code shown in the tab that started it. */
|
|
3825
3879
|
decidePasswordlessApproval(challengeId: string, otp: string, approve: boolean, matchCode?: string): Promise<void>;
|
|
@@ -4321,13 +4375,39 @@ export declare class TwoFactorService {
|
|
|
4321
4375
|
/**
|
|
4322
4376
|
* Begin 2FA setup process
|
|
4323
4377
|
* Returns secret and QR code for authenticator app
|
|
4378
|
+
*
|
|
4379
|
+
* With a setup link's session active the call runs on that session, whoever is signed in here.
|
|
4324
4380
|
*/
|
|
4325
4381
|
beginSetup(): Promise<TwoFactorSetupResponse>;
|
|
4326
4382
|
/**
|
|
4327
4383
|
* Confirm 2FA setup with TOTP code
|
|
4328
4384
|
* Returns recovery codes that MUST be displayed to user
|
|
4385
|
+
*
|
|
4386
|
+
* With a setup link's session active the call runs on that session, which it then ends.
|
|
4329
4387
|
*/
|
|
4330
4388
|
confirmSetup(code: string): Promise<TwoFactorConfirmResponse>;
|
|
4389
|
+
/**
|
|
4390
|
+
* What the sign-in waiting on its second factor can do next. Read this before asking for a code:
|
|
4391
|
+
* the server decides, and only `verify` means the user has a factor to enter a code from.
|
|
4392
|
+
*/
|
|
4393
|
+
getEnrollment(): Promise<TwoFactorEnrollment>;
|
|
4394
|
+
/**
|
|
4395
|
+
* Email the user a link to set up 2FA (`email_link`). They sign in again after enrolling.
|
|
4396
|
+
*/
|
|
4397
|
+
sendSetupLink(): Promise<TwoFactorSetupLinkResponse>;
|
|
4398
|
+
/**
|
|
4399
|
+
* Begin 2FA setup on the sign-in itself (`direct`).
|
|
4400
|
+
*/
|
|
4401
|
+
beginEnrollment(): Promise<TwoFactorSetupResponse>;
|
|
4402
|
+
/**
|
|
4403
|
+
* Confirm 2FA setup on the sign-in itself (`direct`). The sign-in stays pending:
|
|
4404
|
+
* show the recovery codes, then `verify` with the same code finishes it.
|
|
4405
|
+
*/
|
|
4406
|
+
confirmEnrollment(code: string): Promise<TwoFactorConfirmResponse>;
|
|
4407
|
+
private assertTotpCode;
|
|
4408
|
+
private requirePendingTfaToken;
|
|
4409
|
+
private setupStarted;
|
|
4410
|
+
private setupConfirmed;
|
|
4331
4411
|
/**
|
|
4332
4412
|
* Verify TOTP code during login
|
|
4333
4413
|
* Completes authentication if successful
|
|
@@ -4419,7 +4499,7 @@ export declare class TwoFactorService {
|
|
|
4419
4499
|
hasMagicLinkSession(): boolean;
|
|
4420
4500
|
/**
|
|
4421
4501
|
* Get the session token from magic link session (if active)
|
|
4422
|
-
*
|
|
4502
|
+
* `getStatus`, `beginSetup` and `confirmSetup` send it as their bearer while it is active
|
|
4423
4503
|
*/
|
|
4424
4504
|
getMagicLinkSessionToken(): string | null;
|
|
4425
4505
|
/**
|
|
@@ -5837,6 +5917,16 @@ export declare class Passflow {
|
|
|
5837
5917
|
* @param context - Context description for the fallback message
|
|
5838
5918
|
* @throws The original error after handling
|
|
5839
5919
|
*/
|
|
5920
|
+
/**
|
|
5921
|
+
* Asks the server whether this app may redirect to `url`.
|
|
5922
|
+
*
|
|
5923
|
+
* Navigate to the address it resolves to, not the one passed in. Treat any rejection as a refusal.
|
|
5924
|
+
*
|
|
5925
|
+
* @param url - The address to check
|
|
5926
|
+
* @returns The address to navigate to
|
|
5927
|
+
* @throws {PassflowError} `error.app.redirect.url.not.registered` when refused, or a request error
|
|
5928
|
+
*/
|
|
5929
|
+
checkRedirectUrl(url: string): Promise<string>;
|
|
5840
5930
|
private handleError;
|
|
5841
5931
|
/**
|
|
5842
5932
|
* Sign out the current user and clear all tokens.
|
|
@@ -6452,6 +6542,39 @@ export declare class Passflow {
|
|
|
6452
6542
|
* ```
|
|
6453
6543
|
*/
|
|
6454
6544
|
confirmTwoFactorSetup(code: string): Promise<TwoFactorConfirmResponse>;
|
|
6545
|
+
/**
|
|
6546
|
+
* What the sign-in waiting on its second factor can do next. The server decides; read this
|
|
6547
|
+
* before asking for a code, and call `requestChallenge` only on `verify`.
|
|
6548
|
+
*
|
|
6549
|
+
* @returns `verify`: ask for a code. `email_link`: `sendTwoFactorSetupLink`, then the user signs
|
|
6550
|
+
* in again after enrolling. `direct`: `beginTwoFactorEnrollment`, `confirmTwoFactorEnrollment`,
|
|
6551
|
+
* then `verifyTwoFactor`. `unavailable`: tell the user to contact the administrator.
|
|
6552
|
+
* @throws {PassflowError} A 401 means the sign-in is over: sign in again.
|
|
6553
|
+
*/
|
|
6554
|
+
getTwoFactorEnrollment(): Promise<TwoFactorEnrollment>;
|
|
6555
|
+
/**
|
|
6556
|
+
* Email the user a link to set up 2FA, on a sign-in whose enrollment is `email_link`.
|
|
6557
|
+
* The budget is 3 requests in 5 minutes, shared with `requestChallenge`, so limit resends.
|
|
6558
|
+
*
|
|
6559
|
+
* @throws {PassflowError} 503 `error.2fa.setup_link.send_failed` when the email could not be sent
|
|
6560
|
+
*/
|
|
6561
|
+
sendTwoFactorSetupLink(): Promise<TwoFactorSetupLinkResponse>;
|
|
6562
|
+
/**
|
|
6563
|
+
* Begin 2FA setup on the pending sign-in, when its enrollment is `direct`.
|
|
6564
|
+
* Returns a secret and QR code to scan with an authenticator app.
|
|
6565
|
+
*
|
|
6566
|
+
* @throws {PassflowError} 403 `error.2fa.enrollment.not_allowed` in any other state
|
|
6567
|
+
*/
|
|
6568
|
+
beginTwoFactorEnrollment(): Promise<TwoFactorSetupResponse>;
|
|
6569
|
+
/**
|
|
6570
|
+
* Confirm 2FA setup on the pending sign-in. The sign-in stays pending: show the recovery codes,
|
|
6571
|
+
* then `verifyTwoFactor` with the same code finishes it.
|
|
6572
|
+
*
|
|
6573
|
+
* @param code - TOTP code from the authenticator app
|
|
6574
|
+
* @returns Promise with the recovery codes the user must save
|
|
6575
|
+
* @throws {PassflowError} 401 `error.api.request.2fa_code.invalid` on a wrong code
|
|
6576
|
+
*/
|
|
6577
|
+
confirmTwoFactorEnrollment(code: string): Promise<TwoFactorConfirmResponse>;
|
|
6455
6578
|
/**
|
|
6456
6579
|
* Verify a TOTP code during login when 2FA is required.
|
|
6457
6580
|
* Completes the authentication process and saves tokens.
|
package/dist/index.d.ts
CHANGED
|
@@ -1004,6 +1004,7 @@ export declare enum PassflowEndpointPaths {
|
|
|
1004
1004
|
signin = "/auth/login",
|
|
1005
1005
|
signup = "/auth/register",
|
|
1006
1006
|
pkceExchange = "/auth/pkce_exchange",
|
|
1007
|
+
redirectCheck = "/auth/redirect/check",
|
|
1007
1008
|
signInWithProvider = "/auth/federated/start/",
|
|
1008
1009
|
passwordless = "/auth/passwordless/start",
|
|
1009
1010
|
passwordlessComplete = "/auth/passwordless/complete",
|
|
@@ -1042,6 +1043,10 @@ export declare enum PassflowEndpointPaths {
|
|
|
1042
1043
|
twoFactorRecovery = "/auth/2fa/recovery",
|
|
1043
1044
|
twoFactorRegenerateCodes = "/user/2fa/recovery-codes/regenerate",
|
|
1044
1045
|
twoFactorSetupMagicLink = "/auth/2fa-setup", // :token param appended in API call
|
|
1046
|
+
twoFactorEnrollment = "/auth/2fa/enrollment",
|
|
1047
|
+
twoFactorEnrollmentEmailLink = "/auth/2fa/enrollment/email-link",
|
|
1048
|
+
twoFactorEnrollmentBegin = "/auth/2fa/setup/begin",
|
|
1049
|
+
twoFactorEnrollmentConfirm = "/auth/2fa/setup/confirm",
|
|
1045
1050
|
TwoFactorMethodsAvailable = "/v2/user/2fa/methods/available",
|
|
1046
1051
|
TwoFactorMethodsRegistered = "/v2/user/2fa/methods",
|
|
1047
1052
|
TwoFactorSetupStart = "/v2/user/2fa/setup/start",
|
|
@@ -1817,13 +1822,33 @@ export type TwoFactorStatusResponse = {
|
|
|
1817
1822
|
};
|
|
1818
1823
|
export type TwoFactorSetupResponse = {
|
|
1819
1824
|
secret: string;
|
|
1825
|
+
/** Base64-encoded PNG of the QR code. Empty when the server sent no image: use `qr_code_url`. */
|
|
1820
1826
|
qr_code: string;
|
|
1827
|
+
/** The `otpauth://` URL the QR code holds. */
|
|
1828
|
+
qr_code_url?: string;
|
|
1821
1829
|
totp_digits?: 6 | 8;
|
|
1822
1830
|
};
|
|
1823
1831
|
export type TwoFactorConfirmResponse = {
|
|
1824
1832
|
success: true;
|
|
1833
|
+
enabled?: boolean;
|
|
1825
1834
|
recovery_codes: string[];
|
|
1826
1835
|
};
|
|
1836
|
+
/**
|
|
1837
|
+
* What a sign-in waiting on its second factor can do next, decided by the server:
|
|
1838
|
+
* - `verify`: ask for a code; the user has a factor the app accepts.
|
|
1839
|
+
* - `email_link`: no factor yet and a validated email: send the setup link, then the user signs in again.
|
|
1840
|
+
* - `direct`: no factor and no validated email: enrol here, then finish with the code.
|
|
1841
|
+
* - `unavailable`: the app offers no way to enrol this user: contact the administrator.
|
|
1842
|
+
*/
|
|
1843
|
+
export type TwoFactorEnrollment = 'verify' | 'email_link' | 'direct' | 'unavailable';
|
|
1844
|
+
/** GET /auth/2fa/enrollment */
|
|
1845
|
+
export type TwoFactorEnrollmentResponse = {
|
|
1846
|
+
enrollment: TwoFactorEnrollment;
|
|
1847
|
+
};
|
|
1848
|
+
/** POST /auth/2fa/enrollment/email-link */
|
|
1849
|
+
export type TwoFactorSetupLinkResponse = {
|
|
1850
|
+
email_sent: boolean;
|
|
1851
|
+
};
|
|
1827
1852
|
export type TwoFactorVerifyResponse = Tokens & {
|
|
1828
1853
|
success: true;
|
|
1829
1854
|
/** On a PKCE app; `TwoFactorService` redeems it, so its callers never see one. */
|
|
@@ -1872,7 +1897,7 @@ export type TwoFactorRegenerateResponse = {
|
|
|
1872
1897
|
/**
|
|
1873
1898
|
* Two-Factor magic link error codes
|
|
1874
1899
|
*/
|
|
1875
|
-
export type TwoFactorSetupMagicLinkErrorCode = 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'RATE_LIMITED' | 'SERVER_ERROR';
|
|
1900
|
+
export type TwoFactorSetupMagicLinkErrorCode = 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'ALREADY_USED' | 'RATE_LIMITED' | 'SERVER_ERROR';
|
|
1876
1901
|
/**
|
|
1877
1902
|
* Two-Factor magic link error details
|
|
1878
1903
|
*/
|
|
@@ -2140,6 +2165,8 @@ export declare class AuthAPI {
|
|
|
2140
2165
|
passwordlessStatus(payload: PassflowPasswordlessStatusPayload, options?: {
|
|
2141
2166
|
signal?: AbortSignal;
|
|
2142
2167
|
}): Promise<PassflowPasswordlessStatusResponse>;
|
|
2168
|
+
/** Asks the server whether this app may redirect to `url`, and for the address to use. */
|
|
2169
|
+
checkRedirectUrl(url: string): Promise<string>;
|
|
2143
2170
|
/** Reads what the approving device shows. It changes nothing on the server. */
|
|
2144
2171
|
passwordlessApprovalInfo(payload: PassflowPasswordlessApprovalInfoPayload): Promise<PasswordlessApprovalInfo>;
|
|
2145
2172
|
/**
|
|
@@ -2475,20 +2502,46 @@ export declare class TwoFactorApiClient {
|
|
|
2475
2502
|
/**
|
|
2476
2503
|
* Get current 2FA enrollment status
|
|
2477
2504
|
* GET /user/2fa/status
|
|
2505
|
+
*
|
|
2506
|
+
* `setupSessionToken` is a setup link's session; without it the stored session is used.
|
|
2478
2507
|
*/
|
|
2479
|
-
getStatus(): Promise<TwoFactorStatusResponse>;
|
|
2508
|
+
getStatus(setupSessionToken?: string): Promise<TwoFactorStatusResponse>;
|
|
2480
2509
|
/**
|
|
2481
2510
|
* Begin 2FA setup process
|
|
2482
2511
|
* POST /user/2fa/setup/begin
|
|
2483
2512
|
* Returns secret and QR code for authenticator app
|
|
2513
|
+
*
|
|
2514
|
+
* `setupSessionToken` is a setup link's session; without it the stored session is used.
|
|
2484
2515
|
*/
|
|
2485
|
-
beginSetup(): Promise<TwoFactorSetupResponse>;
|
|
2516
|
+
beginSetup(setupSessionToken?: string): Promise<TwoFactorSetupResponse>;
|
|
2486
2517
|
/**
|
|
2487
2518
|
* Confirm 2FA setup with TOTP code
|
|
2488
2519
|
* POST /user/2fa/setup/confirm
|
|
2489
2520
|
* Returns recovery codes on success
|
|
2521
|
+
*
|
|
2522
|
+
* `setupSessionToken` is a setup link's session; without it the stored session is used.
|
|
2523
|
+
*/
|
|
2524
|
+
confirmSetup(payload: TwoFactorConfirmRequest, setupSessionToken?: string): Promise<TwoFactorConfirmResponse>;
|
|
2525
|
+
/**
|
|
2526
|
+
* What a sign-in waiting on its second factor can do next
|
|
2527
|
+
* GET /auth/2fa/enrollment
|
|
2490
2528
|
*/
|
|
2491
|
-
|
|
2529
|
+
getEnrollment(tfaToken: string): Promise<TwoFactorEnrollment>;
|
|
2530
|
+
/**
|
|
2531
|
+
* Email the user a link to set up 2FA
|
|
2532
|
+
* POST /auth/2fa/enrollment/email-link
|
|
2533
|
+
*/
|
|
2534
|
+
sendSetupLink(tfaToken: string): Promise<TwoFactorSetupLinkResponse>;
|
|
2535
|
+
/**
|
|
2536
|
+
* Begin 2FA setup on the sign-in itself, for a user with no validated email
|
|
2537
|
+
* POST /auth/2fa/setup/begin
|
|
2538
|
+
*/
|
|
2539
|
+
beginEnrollment(tfaToken: string): Promise<TwoFactorSetupResponse>;
|
|
2540
|
+
/**
|
|
2541
|
+
* Confirm 2FA setup on the sign-in itself; `verify` with the same code then finishes it
|
|
2542
|
+
* POST /auth/2fa/setup/confirm
|
|
2543
|
+
*/
|
|
2544
|
+
confirmEnrollment(tfaToken: string, payload: TwoFactorConfirmRequest): Promise<TwoFactorConfirmResponse>;
|
|
2492
2545
|
/**
|
|
2493
2546
|
* Verify TOTP code during login
|
|
2494
2547
|
* POST /auth/2fa/verify
|
|
@@ -3393,7 +3446,7 @@ export declare enum PassflowEvent {
|
|
|
3393
3446
|
* The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
|
|
3394
3447
|
* emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
|
|
3395
3448
|
*/
|
|
3396
|
-
type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'passwordless.wait' | 'passwordless.approval' | 'password-reset.send' | 'password-reset.complete' | 'email-verification.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | 'federated.redirect' | 'auth-redirect.url' | 'auth-redirect' | 'auth.is-authenticated' | 'session.check' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | 'settings.app' | 'settings.all' | 'settings.password-policy' | 'settings.passkey' | 'passkey.list' | 'passkey.rename' | 'passkey.delete' | 'passkey.add' | 'tenant.create' | 'invitation.join' | 'invitation.request-link' | 'invitation.list' | 'invitation.delete' | 'invitation.resend' | 'invitation.get-link' | '2fa.status' | '2fa.setup.begin' | '2fa.setup.confirm' | '2fa.verify' | '2fa.recovery.use' | '2fa.disable' | '2fa.recovery.regenerate' | '2fa.methods.available' | '2fa.methods.registered' | '2fa.method.setup.start' | '2fa.method.setup.complete' | '2fa.method.remove' | '2fa.challenge.request' | '2fa.challenge.verify' | '2fa.method.switch' | '2fa.trusted-devices.list' | '2fa.trusted-devices.revoke';
|
|
3449
|
+
type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'passwordless.wait' | 'passwordless.approval' | 'password-reset.send' | 'password-reset.complete' | 'email-verification.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | 'federated.redirect' | 'auth-redirect.url' | 'auth-redirect' | 'redirect.check' | 'auth.is-authenticated' | 'session.check' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | 'settings.app' | 'settings.all' | 'settings.password-policy' | 'settings.passkey' | 'passkey.list' | 'passkey.rename' | 'passkey.delete' | 'passkey.add' | 'tenant.create' | 'invitation.join' | 'invitation.request-link' | 'invitation.list' | 'invitation.delete' | 'invitation.resend' | 'invitation.get-link' | '2fa.status' | '2fa.setup.begin' | '2fa.setup.confirm' | '2fa.enrollment.read' | '2fa.enrollment.setup-link' | '2fa.verify' | '2fa.recovery.use' | '2fa.disable' | '2fa.recovery.regenerate' | '2fa.methods.available' | '2fa.methods.registered' | '2fa.method.setup.start' | '2fa.method.setup.complete' | '2fa.method.remove' | '2fa.challenge.request' | '2fa.challenge.verify' | '2fa.method.switch' | '2fa.trusted-devices.list' | '2fa.trusted-devices.revoke';
|
|
3397
3450
|
/**
|
|
3398
3451
|
* Error payload interface for structured error information
|
|
3399
3452
|
*/
|
|
@@ -3514,7 +3567,7 @@ type PassflowEventPayload = {
|
|
|
3514
3567
|
};
|
|
3515
3568
|
[PassflowEvent.TwoFactorSetupMagicLinkFailed]: {
|
|
3516
3569
|
error: {
|
|
3517
|
-
code: 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'RATE_LIMITED' | 'SERVER_ERROR';
|
|
3570
|
+
code: 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'ALREADY_USED' | 'RATE_LIMITED' | 'SERVER_ERROR';
|
|
3518
3571
|
message: string;
|
|
3519
3572
|
retryAfter?: number;
|
|
3520
3573
|
};
|
|
@@ -3820,6 +3873,7 @@ export declare class AuthService {
|
|
|
3820
3873
|
expiresAt: number;
|
|
3821
3874
|
} | undefined;
|
|
3822
3875
|
/** What the approving device shows about a waiting sign-in. It changes nothing on the server. */
|
|
3876
|
+
checkRedirectUrl(url: string): Promise<string>;
|
|
3823
3877
|
getPasswordlessApproval(challengeId: string): Promise<PasswordlessApprovalInfo>;
|
|
3824
3878
|
/** Approves or denies a waiting sign-in. `matchCode` is the code shown in the tab that started it. */
|
|
3825
3879
|
decidePasswordlessApproval(challengeId: string, otp: string, approve: boolean, matchCode?: string): Promise<void>;
|
|
@@ -4321,13 +4375,39 @@ export declare class TwoFactorService {
|
|
|
4321
4375
|
/**
|
|
4322
4376
|
* Begin 2FA setup process
|
|
4323
4377
|
* Returns secret and QR code for authenticator app
|
|
4378
|
+
*
|
|
4379
|
+
* With a setup link's session active the call runs on that session, whoever is signed in here.
|
|
4324
4380
|
*/
|
|
4325
4381
|
beginSetup(): Promise<TwoFactorSetupResponse>;
|
|
4326
4382
|
/**
|
|
4327
4383
|
* Confirm 2FA setup with TOTP code
|
|
4328
4384
|
* Returns recovery codes that MUST be displayed to user
|
|
4385
|
+
*
|
|
4386
|
+
* With a setup link's session active the call runs on that session, which it then ends.
|
|
4329
4387
|
*/
|
|
4330
4388
|
confirmSetup(code: string): Promise<TwoFactorConfirmResponse>;
|
|
4389
|
+
/**
|
|
4390
|
+
* What the sign-in waiting on its second factor can do next. Read this before asking for a code:
|
|
4391
|
+
* the server decides, and only `verify` means the user has a factor to enter a code from.
|
|
4392
|
+
*/
|
|
4393
|
+
getEnrollment(): Promise<TwoFactorEnrollment>;
|
|
4394
|
+
/**
|
|
4395
|
+
* Email the user a link to set up 2FA (`email_link`). They sign in again after enrolling.
|
|
4396
|
+
*/
|
|
4397
|
+
sendSetupLink(): Promise<TwoFactorSetupLinkResponse>;
|
|
4398
|
+
/**
|
|
4399
|
+
* Begin 2FA setup on the sign-in itself (`direct`).
|
|
4400
|
+
*/
|
|
4401
|
+
beginEnrollment(): Promise<TwoFactorSetupResponse>;
|
|
4402
|
+
/**
|
|
4403
|
+
* Confirm 2FA setup on the sign-in itself (`direct`). The sign-in stays pending:
|
|
4404
|
+
* show the recovery codes, then `verify` with the same code finishes it.
|
|
4405
|
+
*/
|
|
4406
|
+
confirmEnrollment(code: string): Promise<TwoFactorConfirmResponse>;
|
|
4407
|
+
private assertTotpCode;
|
|
4408
|
+
private requirePendingTfaToken;
|
|
4409
|
+
private setupStarted;
|
|
4410
|
+
private setupConfirmed;
|
|
4331
4411
|
/**
|
|
4332
4412
|
* Verify TOTP code during login
|
|
4333
4413
|
* Completes authentication if successful
|
|
@@ -4419,7 +4499,7 @@ export declare class TwoFactorService {
|
|
|
4419
4499
|
hasMagicLinkSession(): boolean;
|
|
4420
4500
|
/**
|
|
4421
4501
|
* Get the session token from magic link session (if active)
|
|
4422
|
-
*
|
|
4502
|
+
* `getStatus`, `beginSetup` and `confirmSetup` send it as their bearer while it is active
|
|
4423
4503
|
*/
|
|
4424
4504
|
getMagicLinkSessionToken(): string | null;
|
|
4425
4505
|
/**
|
|
@@ -5837,6 +5917,16 @@ export declare class Passflow {
|
|
|
5837
5917
|
* @param context - Context description for the fallback message
|
|
5838
5918
|
* @throws The original error after handling
|
|
5839
5919
|
*/
|
|
5920
|
+
/**
|
|
5921
|
+
* Asks the server whether this app may redirect to `url`.
|
|
5922
|
+
*
|
|
5923
|
+
* Navigate to the address it resolves to, not the one passed in. Treat any rejection as a refusal.
|
|
5924
|
+
*
|
|
5925
|
+
* @param url - The address to check
|
|
5926
|
+
* @returns The address to navigate to
|
|
5927
|
+
* @throws {PassflowError} `error.app.redirect.url.not.registered` when refused, or a request error
|
|
5928
|
+
*/
|
|
5929
|
+
checkRedirectUrl(url: string): Promise<string>;
|
|
5840
5930
|
private handleError;
|
|
5841
5931
|
/**
|
|
5842
5932
|
* Sign out the current user and clear all tokens.
|
|
@@ -6452,6 +6542,39 @@ export declare class Passflow {
|
|
|
6452
6542
|
* ```
|
|
6453
6543
|
*/
|
|
6454
6544
|
confirmTwoFactorSetup(code: string): Promise<TwoFactorConfirmResponse>;
|
|
6545
|
+
/**
|
|
6546
|
+
* What the sign-in waiting on its second factor can do next. The server decides; read this
|
|
6547
|
+
* before asking for a code, and call `requestChallenge` only on `verify`.
|
|
6548
|
+
*
|
|
6549
|
+
* @returns `verify`: ask for a code. `email_link`: `sendTwoFactorSetupLink`, then the user signs
|
|
6550
|
+
* in again after enrolling. `direct`: `beginTwoFactorEnrollment`, `confirmTwoFactorEnrollment`,
|
|
6551
|
+
* then `verifyTwoFactor`. `unavailable`: tell the user to contact the administrator.
|
|
6552
|
+
* @throws {PassflowError} A 401 means the sign-in is over: sign in again.
|
|
6553
|
+
*/
|
|
6554
|
+
getTwoFactorEnrollment(): Promise<TwoFactorEnrollment>;
|
|
6555
|
+
/**
|
|
6556
|
+
* Email the user a link to set up 2FA, on a sign-in whose enrollment is `email_link`.
|
|
6557
|
+
* The budget is 3 requests in 5 minutes, shared with `requestChallenge`, so limit resends.
|
|
6558
|
+
*
|
|
6559
|
+
* @throws {PassflowError} 503 `error.2fa.setup_link.send_failed` when the email could not be sent
|
|
6560
|
+
*/
|
|
6561
|
+
sendTwoFactorSetupLink(): Promise<TwoFactorSetupLinkResponse>;
|
|
6562
|
+
/**
|
|
6563
|
+
* Begin 2FA setup on the pending sign-in, when its enrollment is `direct`.
|
|
6564
|
+
* Returns a secret and QR code to scan with an authenticator app.
|
|
6565
|
+
*
|
|
6566
|
+
* @throws {PassflowError} 403 `error.2fa.enrollment.not_allowed` in any other state
|
|
6567
|
+
*/
|
|
6568
|
+
beginTwoFactorEnrollment(): Promise<TwoFactorSetupResponse>;
|
|
6569
|
+
/**
|
|
6570
|
+
* Confirm 2FA setup on the pending sign-in. The sign-in stays pending: show the recovery codes,
|
|
6571
|
+
* then `verifyTwoFactor` with the same code finishes it.
|
|
6572
|
+
*
|
|
6573
|
+
* @param code - TOTP code from the authenticator app
|
|
6574
|
+
* @returns Promise with the recovery codes the user must save
|
|
6575
|
+
* @throws {PassflowError} 401 `error.api.request.2fa_code.invalid` on a wrong code
|
|
6576
|
+
*/
|
|
6577
|
+
confirmTwoFactorEnrollment(code: string): Promise<TwoFactorConfirmResponse>;
|
|
6455
6578
|
/**
|
|
6456
6579
|
* Verify a TOTP code during login when 2FA is required.
|
|
6457
6580
|
* Completes the authentication process and saves tokens.
|