@passflow/core 0.25.0 → 0.27.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.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",
@@ -2164,6 +2165,8 @@ export declare class AuthAPI {
2164
2165
  passwordlessStatus(payload: PassflowPasswordlessStatusPayload, options?: {
2165
2166
  signal?: AbortSignal;
2166
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>;
2167
2170
  /** Reads what the approving device shows. It changes nothing on the server. */
2168
2171
  passwordlessApprovalInfo(payload: PassflowPasswordlessApprovalInfoPayload): Promise<PasswordlessApprovalInfo>;
2169
2172
  /**
@@ -3443,7 +3446,7 @@ export declare enum PassflowEvent {
3443
3446
  * The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
3444
3447
  * emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
3445
3448
  */
3446
- 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.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';
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';
3447
3450
  /**
3448
3451
  * Error payload interface for structured error information
3449
3452
  */
@@ -3474,8 +3477,11 @@ type PassflowEventPayload = {
3474
3477
  parsedTokens?: ParsedTokens;
3475
3478
  /** `'other-tab'` only when an ended tab revives on a new session found in storage. Absent on this tab's own sign-in. */
3476
3479
  origin?: EventOrigin;
3477
- /** Set only when a federated redirect landed here and this instance exchanged its code. */
3478
- source?: 'federated-landing';
3480
+ /**
3481
+ * `'federated-landing'`: a federated redirect landed here and this instance exchanged its code.
3482
+ * `'tokens-in-url'`: tokens received in this page's URL were verified and saved.
3483
+ */
3484
+ source?: 'federated-landing' | 'tokens-in-url';
3479
3485
  };
3480
3486
  [PassflowEvent.SignInStart]: {
3481
3487
  email?: string;
@@ -3870,6 +3876,7 @@ export declare class AuthService {
3870
3876
  expiresAt: number;
3871
3877
  } | undefined;
3872
3878
  /** What the approving device shows about a waiting sign-in. It changes nothing on the server. */
3879
+ checkRedirectUrl(url: string): Promise<string>;
3873
3880
  getPasswordlessApproval(challengeId: string): Promise<PasswordlessApprovalInfo>;
3874
3881
  /** Approves or denies a waiting sign-in. `matchCode` is the code shown in the tab that started it. */
3875
3882
  decidePasswordlessApproval(challengeId: string, otp: string, approve: boolean, matchCode?: string): Promise<void>;
@@ -5606,26 +5613,29 @@ export declare class Passflow {
5606
5613
  */
5607
5614
  unsubscribe(subscriber: PassflowSubscriber, events?: PassflowEvent[]): void;
5608
5615
  /**
5609
- * Handle OAuth redirect callback and extract tokens from URL query parameters.
5616
+ * Handle OAuth redirect callback and take tokens from the URL query or fragment.
5610
5617
  * This method should be called on the redirect page after authentication.
5611
5618
  *
5612
- * @returns Tokens object if found in URL, undefined otherwise
5619
+ * The tokens are removed from the URL at once, then verified in the background against the
5620
+ * configured server's published keys and this app id (required). `SignIn` with
5621
+ * `source: 'tokens-in-url'` (tokens saved), or `Error` with operation `tokens.from-url` (nothing
5622
+ * saved), reports the outcome, so subscribe first.
5613
5623
  *
5614
5624
  * @example
5615
5625
  * ```typescript
5616
5626
  * // On your redirect page (e.g., /auth/callback)
5617
- * const tokens = passflow.handleTokensRedirect();
5618
- * if (tokens) {
5619
- * console.log('Authentication successful', tokens.access_token);
5620
- * // Tokens are automatically saved to storage
5621
- * }
5627
+ * passflow.subscribe(
5628
+ * { onAuthChange: (event, payload) => console.log(event, payload) },
5629
+ * [PassflowEvent.SignIn, PassflowEvent.Error],
5630
+ * );
5631
+ * passflow.handleTokensRedirect();
5622
5632
  * ```
5623
5633
  *
5624
5634
  * A PKCE federated landing (`?code=`) returns `undefined` and finishes in the background: `SignIn`
5625
5635
  * or `TwoFactorRequired` is the signal. With `deferFederatedLanding` it is left to
5626
5636
  * `completeFederatedLanding()`.
5627
5637
  */
5628
- handleTokensRedirect(): Tokens | undefined;
5638
+ handleTokensRedirect(): void;
5629
5639
  /**
5630
5640
  * Takes a PKCE federated landing (`?code=&user_state=`) on this page, for an instance built with
5631
5641
  * `deferFederatedLanding`. The code is exchanged in the background; `SignIn` with
@@ -5651,6 +5661,10 @@ export declare class Passflow {
5651
5661
  */
5652
5662
  private adoptTwoFactorTokenFromUrl;
5653
5663
  private checkErrorsFromURL;
5664
+ /**
5665
+ * When a token appears in the query or the fragment, removes every token from the query and drops
5666
+ * a token-carrying fragment, in one history replace. Other query params stay.
5667
+ */
5654
5668
  private cleanupUrlParams;
5655
5669
  private setTokensToCacheFromLocalStorage;
5656
5670
  /**
@@ -5913,6 +5927,16 @@ export declare class Passflow {
5913
5927
  * @param context - Context description for the fallback message
5914
5928
  * @throws The original error after handling
5915
5929
  */
5930
+ /**
5931
+ * Asks the server whether this app may redirect to `url`.
5932
+ *
5933
+ * Navigate to the address it resolves to, not the one passed in. Treat any rejection as a refusal.
5934
+ *
5935
+ * @param url - The address to check
5936
+ * @returns The address to navigate to
5937
+ * @throws {PassflowError} `error.app.redirect.url.not.registered` when refused, or a request error
5938
+ */
5939
+ checkRedirectUrl(url: string): Promise<string>;
5916
5940
  private handleError;
5917
5941
  /**
5918
5942
  * Sign out the current user and clear all 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",
@@ -2164,6 +2165,8 @@ export declare class AuthAPI {
2164
2165
  passwordlessStatus(payload: PassflowPasswordlessStatusPayload, options?: {
2165
2166
  signal?: AbortSignal;
2166
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>;
2167
2170
  /** Reads what the approving device shows. It changes nothing on the server. */
2168
2171
  passwordlessApprovalInfo(payload: PassflowPasswordlessApprovalInfoPayload): Promise<PasswordlessApprovalInfo>;
2169
2172
  /**
@@ -3443,7 +3446,7 @@ export declare enum PassflowEvent {
3443
3446
  * The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
3444
3447
  * emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
3445
3448
  */
3446
- 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.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';
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';
3447
3450
  /**
3448
3451
  * Error payload interface for structured error information
3449
3452
  */
@@ -3474,8 +3477,11 @@ type PassflowEventPayload = {
3474
3477
  parsedTokens?: ParsedTokens;
3475
3478
  /** `'other-tab'` only when an ended tab revives on a new session found in storage. Absent on this tab's own sign-in. */
3476
3479
  origin?: EventOrigin;
3477
- /** Set only when a federated redirect landed here and this instance exchanged its code. */
3478
- source?: 'federated-landing';
3480
+ /**
3481
+ * `'federated-landing'`: a federated redirect landed here and this instance exchanged its code.
3482
+ * `'tokens-in-url'`: tokens received in this page's URL were verified and saved.
3483
+ */
3484
+ source?: 'federated-landing' | 'tokens-in-url';
3479
3485
  };
3480
3486
  [PassflowEvent.SignInStart]: {
3481
3487
  email?: string;
@@ -3870,6 +3876,7 @@ export declare class AuthService {
3870
3876
  expiresAt: number;
3871
3877
  } | undefined;
3872
3878
  /** What the approving device shows about a waiting sign-in. It changes nothing on the server. */
3879
+ checkRedirectUrl(url: string): Promise<string>;
3873
3880
  getPasswordlessApproval(challengeId: string): Promise<PasswordlessApprovalInfo>;
3874
3881
  /** Approves or denies a waiting sign-in. `matchCode` is the code shown in the tab that started it. */
3875
3882
  decidePasswordlessApproval(challengeId: string, otp: string, approve: boolean, matchCode?: string): Promise<void>;
@@ -5606,26 +5613,29 @@ export declare class Passflow {
5606
5613
  */
5607
5614
  unsubscribe(subscriber: PassflowSubscriber, events?: PassflowEvent[]): void;
5608
5615
  /**
5609
- * Handle OAuth redirect callback and extract tokens from URL query parameters.
5616
+ * Handle OAuth redirect callback and take tokens from the URL query or fragment.
5610
5617
  * This method should be called on the redirect page after authentication.
5611
5618
  *
5612
- * @returns Tokens object if found in URL, undefined otherwise
5619
+ * The tokens are removed from the URL at once, then verified in the background against the
5620
+ * configured server's published keys and this app id (required). `SignIn` with
5621
+ * `source: 'tokens-in-url'` (tokens saved), or `Error` with operation `tokens.from-url` (nothing
5622
+ * saved), reports the outcome, so subscribe first.
5613
5623
  *
5614
5624
  * @example
5615
5625
  * ```typescript
5616
5626
  * // On your redirect page (e.g., /auth/callback)
5617
- * const tokens = passflow.handleTokensRedirect();
5618
- * if (tokens) {
5619
- * console.log('Authentication successful', tokens.access_token);
5620
- * // Tokens are automatically saved to storage
5621
- * }
5627
+ * passflow.subscribe(
5628
+ * { onAuthChange: (event, payload) => console.log(event, payload) },
5629
+ * [PassflowEvent.SignIn, PassflowEvent.Error],
5630
+ * );
5631
+ * passflow.handleTokensRedirect();
5622
5632
  * ```
5623
5633
  *
5624
5634
  * A PKCE federated landing (`?code=`) returns `undefined` and finishes in the background: `SignIn`
5625
5635
  * or `TwoFactorRequired` is the signal. With `deferFederatedLanding` it is left to
5626
5636
  * `completeFederatedLanding()`.
5627
5637
  */
5628
- handleTokensRedirect(): Tokens | undefined;
5638
+ handleTokensRedirect(): void;
5629
5639
  /**
5630
5640
  * Takes a PKCE federated landing (`?code=&user_state=`) on this page, for an instance built with
5631
5641
  * `deferFederatedLanding`. The code is exchanged in the background; `SignIn` with
@@ -5651,6 +5661,10 @@ export declare class Passflow {
5651
5661
  */
5652
5662
  private adoptTwoFactorTokenFromUrl;
5653
5663
  private checkErrorsFromURL;
5664
+ /**
5665
+ * When a token appears in the query or the fragment, removes every token from the query and drops
5666
+ * a token-carrying fragment, in one history replace. Other query params stay.
5667
+ */
5654
5668
  private cleanupUrlParams;
5655
5669
  private setTokensToCacheFromLocalStorage;
5656
5670
  /**
@@ -5913,6 +5927,16 @@ export declare class Passflow {
5913
5927
  * @param context - Context description for the fallback message
5914
5928
  * @throws The original error after handling
5915
5929
  */
5930
+ /**
5931
+ * Asks the server whether this app may redirect to `url`.
5932
+ *
5933
+ * Navigate to the address it resolves to, not the one passed in. Treat any rejection as a refusal.
5934
+ *
5935
+ * @param url - The address to check
5936
+ * @returns The address to navigate to
5937
+ * @throws {PassflowError} `error.app.redirect.url.not.registered` when refused, or a request error
5938
+ */
5939
+ checkRedirectUrl(url: string): Promise<string>;
5916
5940
  private handleError;
5917
5941
  /**
5918
5942
  * Sign out the current user and clear all tokens.