@vunexa/lixa 0.1.6-alpha.13 → 0.1.6-alpha.14

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
@@ -101,9 +101,9 @@ interface ConnectedResource {
101
101
  */
102
102
  interface Session<TRaw = OAuthTokenResponse> {
103
103
  /**
104
- * Unique session ID generated by Lixa upon authentication.
104
+ * Unique canonical session ID generated by Lixa upon authentication.
105
105
  */
106
- id?: string | undefined;
106
+ sessionId?: string | undefined;
107
107
  /**
108
108
  * Linked identity provider accounts (AuthN) keyed by provider name.
109
109
  * Single source of truth for all authenticated user SSO identities.
@@ -427,6 +427,25 @@ interface ResourceStorage {
427
427
  interface ResourceHandler {
428
428
  resourceStorage?: ResourceStorage;
429
429
  }
430
+ /**
431
+ * Interface for persistent linked account storage across user sessions.
432
+ *
433
+ * @public
434
+ */
435
+ interface AccountStorage {
436
+ saveAccount(userId: string, provider: string, account: LinkedAccount): Promise<void>;
437
+ getAccount(userId: string, provider: string): Promise<LinkedAccount | null>;
438
+ getUserAccounts(userId: string): Promise<Record<string, LinkedAccount>>;
439
+ deleteAccount(userId: string, provider: string): Promise<void>;
440
+ }
441
+ /**
442
+ * Account handler configuration.
443
+ *
444
+ * @public
445
+ */
446
+ interface AccountHandler {
447
+ accountStorage?: AccountStorage;
448
+ }
430
449
  /**
431
450
  * Session handler for OAuth authentication.
432
451
  *
@@ -658,8 +677,235 @@ interface IProvider {
658
677
  * @example ['openid', 'email', 'profile'] or ['read:user', 'user:email']
659
678
  */
660
679
  authScopes?: string[];
680
+ /**
681
+ * Default OAuth scopes requested when not explicitly specified in ProviderConfig.
682
+ */
683
+ defaultScopes?: string[];
661
684
  }
662
685
 
686
+ /**
687
+ * Standardized user identity representation across all identity providers
688
+ * (Self-Managed Database, AWS Cognito, Auth0, Okta, Firebase, etc.).
689
+ *
690
+ * @public
691
+ */
692
+ interface UserIdentity {
693
+ /** Unique user identifier (UUID, Sub, Auth0 user_id, Okta id) */
694
+ id: string;
695
+ /** Primary unique lookup identifier (email or username) */
696
+ identifier: string;
697
+ /** Associated email address if available */
698
+ email?: string | undefined;
699
+ /** Username of the account if available */
700
+ username?: string | undefined;
701
+ /** Whether the email address has been verified by the identity provider */
702
+ emailVerified?: boolean | undefined;
703
+ /** Unix timestamp in milliseconds when user was created */
704
+ createdAt?: number | undefined;
705
+ /** Unix timestamp in milliseconds when user was last updated */
706
+ updatedAt?: number | undefined;
707
+ /** Custom user metadata or profile attributes */
708
+ metadata?: Record<string, unknown> | undefined;
709
+ /** Identity provider name (e.g. "self-managed", "cognito", "auth0", "okta") */
710
+ provider?: string | undefined;
711
+ }
712
+ /**
713
+ * Standardized token response from an identity provider.
714
+ *
715
+ * @public
716
+ */
717
+ interface IdentityTokens {
718
+ /** OAuth / IdP Access Token (JWT or opaque token) */
719
+ accessToken?: string | undefined;
720
+ /** OpenID Connect ID Token containing user claims */
721
+ idToken?: string | undefined;
722
+ /** Refresh token for renewing expired credentials */
723
+ refreshToken?: string | undefined;
724
+ /** Token type (usually "Bearer") */
725
+ tokenType?: string | undefined;
726
+ /** Token expiration time in seconds */
727
+ expiresIn?: number | undefined;
728
+ /** Raw response object returned directly by the provider */
729
+ raw?: Record<string, unknown> | undefined;
730
+ }
731
+ /**
732
+ * Result of user authentication through an identity provider.
733
+ *
734
+ * @public
735
+ */
736
+ interface IdentityAuthResult {
737
+ /** Authenticated user profile */
738
+ user: UserIdentity;
739
+ /** Optional tokens issued by the identity provider */
740
+ tokens?: IdentityTokens | undefined;
741
+ }
742
+ /**
743
+ * Parameters for requesting a password reset (forgot password).
744
+ *
745
+ * @public
746
+ */
747
+ interface ForgotPasswordParams {
748
+ /** Username or email of the account requesting a password reset */
749
+ identifier: string;
750
+ /** Optional custom client metadata or redirect URL */
751
+ metadata?: Record<string, unknown> | undefined;
752
+ }
753
+ /**
754
+ * Result of a password reset request.
755
+ *
756
+ * @public
757
+ */
758
+ interface ForgotPasswordResult {
759
+ /** Whether the password reset request was accepted */
760
+ success: boolean;
761
+ /** Delivery destination description (e.g. masked email: a***@example.com or phone) */
762
+ deliveryMedium?: string | undefined;
763
+ /** Optional message or status code from provider */
764
+ message?: string | undefined;
765
+ }
766
+ /**
767
+ * Parameters for confirming a password reset with a confirmation code or token.
768
+ *
769
+ * @public
770
+ */
771
+ interface ConfirmPasswordResetParams {
772
+ /** Username or email of the account */
773
+ identifier: string;
774
+ /** Verification code (e.g. 6-digit OTP from email/SMS) or reset token */
775
+ confirmationCode: string;
776
+ /** New plaintext password */
777
+ newPassword: string;
778
+ }
779
+ /**
780
+ * Parameters for confirming user registration with a verification code.
781
+ *
782
+ * @public
783
+ */
784
+ interface ConfirmSignUpParams {
785
+ /** Username or email of the account to confirm */
786
+ identifier: string;
787
+ /** Verification code (e.g. 6-digit OTP from email/SMS) */
788
+ confirmationCode: string;
789
+ }
790
+ /**
791
+ * Parameters for resending a sign up confirmation code.
792
+ *
793
+ * @public
794
+ */
795
+ interface ResendConfirmationCodeParams {
796
+ /** Username or email of the account */
797
+ identifier: string;
798
+ }
799
+ /**
800
+ * Result of resending a sign up confirmation code.
801
+ *
802
+ * @public
803
+ */
804
+ interface ResendConfirmationCodeResult {
805
+ /** True if code was dispatched */
806
+ success: boolean;
807
+ /** Delivery medium (e.g. 'EMAIL' or 'SMS') */
808
+ deliveryMedium?: string | undefined;
809
+ /** Obscured destination */
810
+ destination?: string | undefined;
811
+ }
812
+ /**
813
+ * Unified interface for Identity Providers in Lixa.
814
+ *
815
+ * @remarks
816
+ * Implement this interface to create custom identity providers (e.g. Supabase Auth,
817
+ * Firebase Auth, Keycloak, or proprietary enterprise directories).
818
+ *
819
+ * Built-in extensions for AWS Cognito, Auth0, and Okta are available in `@vunexa/lixa-extensions`.
820
+ *
821
+ * @public
822
+ */
823
+ interface IIdentityProvider {
824
+ /**
825
+ * Unique name of the identity provider.
826
+ * Examples: 'self-managed', 'cognito', 'auth0', 'okta'
827
+ */
828
+ readonly name: string;
829
+ /**
830
+ * Registers a new user with the identity provider.
831
+ *
832
+ * @param params - User registration details (identifier, password, email, username, metadata)
833
+ * @returns Created user identity
834
+ */
835
+ signUp(params: SignUpParams): Promise<UserIdentity>;
836
+ /**
837
+ * Authenticates a user with credentials.
838
+ *
839
+ * @param params - Sign in credentials (identifier, password)
840
+ * @returns Authenticated user identity and optional provider tokens
841
+ */
842
+ signIn(params: SignInParams): Promise<IdentityAuthResult>;
843
+ /**
844
+ * Verifies credentials without necessarily creating a full session.
845
+ *
846
+ * @param params - Verification parameters
847
+ * @returns User identity if credentials are valid, null otherwise
848
+ */
849
+ verifyCredentials?(params: VerifyCredentialsParams): Promise<UserIdentity | null>;
850
+ /**
851
+ * Changes a user's password.
852
+ *
853
+ * @param params - Old password, new password, and user identifier
854
+ * @returns True if password was successfully updated
855
+ */
856
+ changePassword?(params: ChangePasswordParams): Promise<boolean>;
857
+ /**
858
+ * Requests a password reset (forgot password flow).
859
+ *
860
+ * @param params - Forgot password parameters
861
+ */
862
+ forgotPassword?(params: ForgotPasswordParams): Promise<ForgotPasswordResult>;
863
+ /**
864
+ * Confirms password reset with verification code and new password.
865
+ *
866
+ * @param params - Confirm password reset parameters
867
+ */
868
+ confirmPasswordReset?(params: ConfirmPasswordResetParams): Promise<boolean>;
869
+ /**
870
+ * Confirms user registration using a verification code.
871
+ *
872
+ * @param params - Confirm sign up parameters
873
+ */
874
+ confirmSignUp?(params: ConfirmSignUpParams): Promise<boolean>;
875
+ /**
876
+ * Resends the sign up confirmation code.
877
+ *
878
+ * @param params - Resend confirmation code parameters
879
+ */
880
+ resendConfirmationCode?(params: ResendConfirmationCodeParams): Promise<ResendConfirmationCodeResult>;
881
+ /**
882
+ * Retrieves a user by their unique ID.
883
+ *
884
+ * @param id - Unique user ID
885
+ */
886
+ getUserById?(id: string): Promise<UserIdentity | null>;
887
+ /**
888
+ * Retrieves a user by their identifier (email or username).
889
+ *
890
+ * @param identifier - Username or email string
891
+ */
892
+ getUserByIdentifier?(identifier: string): Promise<UserIdentity | null>;
893
+ /**
894
+ * Deletes a user account.
895
+ *
896
+ * @param id - Unique user ID
897
+ */
898
+ deleteUser?(id: string): Promise<void>;
899
+ }
900
+ /**
901
+ * Configuration options for Identity Providers in LixaConfig.
902
+ *
903
+ * @public
904
+ */
905
+ type IdentityConfig = IIdentityProvider | ({
906
+ provider?: "self-managed";
907
+ } & CredentialsConfig);
908
+
663
909
  /**
664
910
  * User credentials entity representing stored account login information.
665
911
  *
@@ -908,9 +1154,9 @@ interface SignUpParams {
908
1154
  *
909
1155
  * @public
910
1156
  */
911
- interface SignUpResult<TSession = Session> {
912
- /** Created user credentials (with passwordHash omitted for safety) */
913
- user: Omit<UserCredentials, "passwordHash">;
1157
+ interface SignUpResult<TSession = Session, TUser = UserIdentity> {
1158
+ /** Created user profile / credentials (with passwordHash omitted for safety) */
1159
+ user: TUser;
914
1160
  /** Created session ID if autoCreateSessionOnSignUp is enabled */
915
1161
  sessionId?: string | undefined;
916
1162
  /** Created session object if autoCreateSessionOnSignUp is enabled */
@@ -934,9 +1180,9 @@ interface SignInParams {
934
1180
  *
935
1181
  * @public
936
1182
  */
937
- interface SignInResult<TSession = Session> {
938
- /** Authenticated user credentials (with passwordHash omitted for safety) */
939
- user: Omit<UserCredentials, "passwordHash">;
1183
+ interface SignInResult<TSession = Session, TUser = UserIdentity> {
1184
+ /** Authenticated user profile / credentials (with passwordHash omitted for safety) */
1185
+ user: TUser;
940
1186
  /** Active session ID */
941
1187
  sessionId: string;
942
1188
  /** Active session object */
@@ -1154,6 +1400,55 @@ declare class CredentialsManager {
1154
1400
  getHasher(): IPasswordHasher;
1155
1401
  }
1156
1402
 
1403
+ /**
1404
+ * Self-Managed Identity Provider implementation for Lixa.
1405
+ *
1406
+ * @remarks
1407
+ * Backed by custom database storage (Prisma, Drizzle, PostgreSQL, SQLite, MongoDB)
1408
+ * or local in-memory storage, with cryptographic password hashing (Scrypt, Argon2, PBKDF2)
1409
+ * and configurable password policy enforcement.
1410
+ *
1411
+ * @public
1412
+ */
1413
+ declare class SelfManagedIdentityProvider implements IIdentityProvider {
1414
+ readonly name: string;
1415
+ private readonly manager;
1416
+ constructor(configOrManager?: CredentialsConfig | CredentialsManager);
1417
+ private mapUser;
1418
+ /**
1419
+ * Registers a new user.
1420
+ */
1421
+ signUp(params: SignUpParams): Promise<UserIdentity>;
1422
+ /**
1423
+ * Authenticates a user with password.
1424
+ */
1425
+ signIn(params: SignInParams): Promise<IdentityAuthResult>;
1426
+ /**
1427
+ * Verifies credentials without throwing an error if invalid.
1428
+ */
1429
+ verifyCredentials(params: VerifyCredentialsParams): Promise<UserIdentity | null>;
1430
+ /**
1431
+ * Changes a user's password.
1432
+ */
1433
+ changePassword(params: ChangePasswordParams): Promise<boolean>;
1434
+ /**
1435
+ * Retrieves a user by their unique ID.
1436
+ */
1437
+ getUserById(id: string): Promise<UserIdentity | null>;
1438
+ /**
1439
+ * Retrieves a user by their identifier (email or username).
1440
+ */
1441
+ getUserByIdentifier(identifier: string): Promise<UserIdentity | null>;
1442
+ /**
1443
+ * Deletes a user from storage if supported by the storage adapter.
1444
+ */
1445
+ deleteUser(id: string): Promise<void>;
1446
+ /**
1447
+ * Returns the underlying CredentialsManager instance.
1448
+ */
1449
+ getCredentialsManager(): CredentialsManager;
1450
+ }
1451
+
1157
1452
  /**
1158
1453
  * Configuration for an OAuth provider instance.
1159
1454
  *
@@ -1197,8 +1492,13 @@ type ProviderConfig = {
1197
1492
  clientSecret: string;
1198
1493
  /** The redirect URI registered with the provider */
1199
1494
  redirectUri: string;
1200
- /** Array of OAuth scopes to request */
1201
- scopes: string[];
1495
+ /** Array of OAuth scopes to request. If omitted, uses provider default identity scopes. */
1496
+ scopes?: string[];
1497
+ /**
1498
+ * Default scopes requested when connecting this provider as a third-party resource (AuthZ).
1499
+ * Used automatically by getResourceAuthUrl() and handleResourceCallback() if not overridden at runtime.
1500
+ */
1501
+ resourceScopes?: string[];
1202
1502
  /**
1203
1503
  * Set to true to allow non-identity (resource) scopes during primary authentication flow.
1204
1504
  * By default (false), Lixa restricts primary AuthN scopes to identity scopes to maintain
@@ -1316,6 +1616,18 @@ interface AccountLinkingConfig {
1316
1616
  */
1317
1617
  requireVerifiedEmail?: boolean;
1318
1618
  }
1619
+ /**
1620
+ * Unified storage adapter interface (e.g. Prisma or Drizzle adapter).
1621
+ * When provided to Lixa via config.storage, automatically configures session, state, and resource storage.
1622
+ * @public
1623
+ */
1624
+ interface StorageAdapter {
1625
+ sessionStorage?: any;
1626
+ resourceStorage?: any;
1627
+ stateStorage?: any;
1628
+ credentialsStorage?: any;
1629
+ accountStorage?: any;
1630
+ }
1319
1631
  /**
1320
1632
  * Main configuration object for Lixa.
1321
1633
  * Provides type-safe provider name inference.
@@ -1324,18 +1636,50 @@ interface AccountLinkingConfig {
1324
1636
  */
1325
1637
  interface LixaConfig<TProviders extends Record<string, ProviderConfig> = Record<string, ProviderConfig>> {
1326
1638
  /**
1327
- * Map of provider names to their configurations.
1639
+ * Map of federated OAuth 2.0 / OIDC provider names to their configurations (Google, GitHub, etc.)
1640
+ * that federate with and work alongside the primary identityProvider.
1328
1641
  * Provider names will be available for autocomplete in getAuthUrl() and handleCallback().
1329
1642
  */
1643
+ federatedOAuthProviders?: TProviders;
1644
+ /**
1645
+ * Alias for {@link LixaConfig.federatedOAuthProviders}.
1646
+ */
1330
1647
  providers?: TProviders;
1648
+ /**
1649
+ * Primary Identity Provider configuration (Self-Managed Database, AWS Cognito, Auth0, Okta, or custom IIdentityProvider).
1650
+ *
1651
+ * @example
1652
+ * Self-managed with Prisma:
1653
+ * ```typescript
1654
+ * identityProvider: { storage: prismaAdapter.credentialsStorage }
1655
+ * ```
1656
+ *
1657
+ * @example
1658
+ * AWS Cognito:
1659
+ * ```typescript
1660
+ * identityProvider: new CognitoIdentityProvider({ userPoolId: '...', clientId: '...', region: 'us-east-1' })
1661
+ * ```
1662
+ */
1663
+ identityProvider?: IIdentityProvider | IdentityConfig;
1664
+ /**
1665
+ * Alias for {@link LixaConfig.identityProvider}.
1666
+ */
1667
+ identity?: IIdentityProvider | IdentityConfig;
1331
1668
  /**
1332
1669
  * Credentials (username and password) authentication configuration.
1670
+ * Automatically maps to a SelfManagedIdentityProvider.
1333
1671
  */
1334
1672
  credentials?: CredentialsConfig;
1673
+ /**
1674
+ * Unified database storage adapter (e.g. createPrismaAdapter or createDrizzleAdapter).
1675
+ * Automatically configures sessionHandler, stateHandler, and resourceHandler.
1676
+ */
1677
+ storage?: StorageAdapter;
1335
1678
  /**
1336
1679
  * Account linking configuration for multi-SSO user linking.
1680
+ * Pass `true` or `"linkByEmail"` for automatic email-verified linking.
1337
1681
  */
1338
- accountLinking?: AccountLinkingConfig;
1682
+ accountLinking?: boolean | AccountLinkingMode | AccountLinkingConfig;
1339
1683
  /**
1340
1684
  * Optional custom state handler.
1341
1685
  * Handles state generation and storage during OAuth authorization flow.
@@ -1379,7 +1723,30 @@ interface LixaConfig<TProviders extends Record<string, ProviderConfig> = Record<
1379
1723
  * If provided, all Lixa logs will be routed through this logger.
1380
1724
  */
1381
1725
  logger?: LixaLogger;
1726
+ /**
1727
+ * Session cookie name or dynamic resolution function.
1728
+ * Can accept a static string or `(lixa: Lixa, req?: unknown) => string`.
1729
+ * Automatically evaluated live against the instance when getSessionCookieName() is called.
1730
+ */
1731
+ sessionCookieName?: SessionCookieResolver;
1732
+ }
1733
+ /**
1734
+ * Interface exposing identity information for dynamic session cookie name resolution.
1735
+ * @public
1736
+ */
1737
+ interface LixaCookieContext {
1738
+ /**
1739
+ * Retrieves the currently active identity provider.
1740
+ */
1741
+ getIdentityProvider(): IIdentityProvider | undefined;
1382
1742
  }
1743
+ /**
1744
+ * Dynamic resolver for session cookie name.
1745
+ * Can be a static string or a dynamic callback receiving the Lixa instance and an optional request context.
1746
+ *
1747
+ * @public
1748
+ */
1749
+ type SessionCookieResolver<TContext extends LixaCookieContext = LixaCookieContext> = string | ((lixa: TContext, req?: unknown) => string);
1383
1750
  /**
1384
1751
  * Log level for Lixa structured logging.
1385
1752
  * @public
@@ -1389,7 +1756,7 @@ type LogLevel = "INFO" | "WARN" | "ERROR" | "DEBUG";
1389
1756
  * Log context for Lixa structured logging.
1390
1757
  * @public
1391
1758
  */
1392
- type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource" | "Credentials";
1759
+ type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource" | "Credentials" | "Identity";
1393
1760
  /**
1394
1761
  * Custom logger interface for Lixa.
1395
1762
  * @public
@@ -1413,7 +1780,7 @@ type SafeLixaConfig<TProviders extends Record<string, ProviderConfig>> = LixaCon
1413
1780
  /**
1414
1781
  * Type representing the keys of configured providers
1415
1782
  */
1416
- type ConfiguredProviderKey<T extends LixaConfig<Record<string, ProviderConfig>>> = keyof T['providers'];
1783
+ type ConfiguredProviderKey<TProviders extends Record<string, ProviderConfig>> = keyof TProviders & string;
1417
1784
  /**
1418
1785
  * A flexible, provider-agnostic OAuth 2.0 and OpenID Connect (OIDC) client library.
1419
1786
  *
@@ -1466,20 +1833,25 @@ type ConfiguredProviderKey<T extends LixaConfig<Record<string, ProviderConfig>>>
1466
1833
  *
1467
1834
  * @public
1468
1835
  */
1469
- declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> = LixaConfig> {
1836
+ declare class Lixa<TProviders extends Record<string, ProviderConfig> = Record<string, ProviderConfig>> {
1470
1837
  private static DEFAULT_PROVIDERS;
1471
1838
  private static CONFIGURED_PROVIDERS;
1472
1839
  private localStateHandler;
1473
1840
  private localSessionHandler;
1474
1841
  private localResourceHandler;
1842
+ private localAccountHandler;
1475
1843
  private userResourceStore;
1844
+ private userAccountStore;
1476
1845
  private refreshMutexes;
1846
+ private identityProvider?;
1477
1847
  private credentialsManager?;
1478
1848
  private config;
1479
1849
  private stateHandler;
1480
1850
  private sessionHandler;
1481
1851
  private resourceHandler;
1852
+ private accountHandler;
1482
1853
  private debug;
1854
+ private sessionCookieResolver?;
1483
1855
  /**
1484
1856
  * Creates a new Lixa instance with the provided configuration.
1485
1857
  *
@@ -1493,7 +1865,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1493
1865
  * @throws Error when provider implementation is missing required properties
1494
1866
  * @throws Error when provider is not available and no inline implementation is provided
1495
1867
  */
1496
- constructor(config: TConfig);
1868
+ constructor(config: LixaConfig<TProviders>);
1497
1869
  /**
1498
1870
  * Validates that a provider configuration has all required credentials.
1499
1871
  *
@@ -1534,7 +1906,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1534
1906
  * }
1535
1907
  * ```
1536
1908
  */
1537
- isProviderConfigured<T extends string>(provider: T): provider is T & ConfiguredProviderKey<TConfig>;
1909
+ isProviderConfigured<T extends string>(provider: T): provider is T & ConfiguredProviderKey<TProviders>;
1538
1910
  /**
1539
1911
  * Gets a provider implementation by name.
1540
1912
  * Resolution priority: inline custom provider \> default providers \> legacy registry
@@ -1715,7 +2087,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1715
2087
  * res.redirect(authUrl);
1716
2088
  * ```
1717
2089
  */
1718
- getAuthUrl(provider: ConfiguredProviderKey<TConfig> | string, state?: string): Promise<string>;
2090
+ getAuthUrl(provider: ConfiguredProviderKey<TProviders> | string, state?: string): Promise<string>;
1719
2091
  /**
1720
2092
  * Restricts primary authentication scopes strictly to AuthN identity scopes unless allowNonAuthScopes is true.
1721
2093
  */
@@ -1739,10 +2111,11 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1739
2111
  * });
1740
2112
  * ```
1741
2113
  */
1742
- handleCallback({ provider, code, state, }: {
1743
- provider: ConfiguredProviderKey<TConfig> | string;
2114
+ handleCallback({ provider, code, state, sessionId, }: {
2115
+ provider: ConfiguredProviderKey<TProviders> | string;
1744
2116
  code: string;
1745
2117
  state?: string;
2118
+ sessionId?: string;
1746
2119
  }): Promise<string>;
1747
2120
  /**
1748
2121
  * Explicitly link a new OAuth provider account to an active session.
@@ -1752,7 +2125,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1752
2125
  */
1753
2126
  linkAccount(params: {
1754
2127
  sessionId: string;
1755
- provider: ConfiguredProviderKey<TConfig> | string;
2128
+ provider: ConfiguredProviderKey<TProviders> | string;
1756
2129
  code: string;
1757
2130
  state?: string;
1758
2131
  }): Promise<string>;
@@ -1777,8 +2150,8 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1777
2150
  */
1778
2151
  getResourceAuthUrl(params: {
1779
2152
  sessionId: string;
1780
- provider: ConfiguredProviderKey<TConfig> | string;
1781
- scopes: string[];
2153
+ provider: ConfiguredProviderKey<TProviders> | string;
2154
+ scopes?: string[];
1782
2155
  state?: string;
1783
2156
  prompt?: string;
1784
2157
  extraConfig?: Record<string, string>;
@@ -1789,11 +2162,32 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1789
2162
  */
1790
2163
  handleResourceCallback(params: {
1791
2164
  sessionId: string;
1792
- provider: ConfiguredProviderKey<TConfig> | string;
2165
+ provider: ConfiguredProviderKey<TProviders> | string;
1793
2166
  code: string;
1794
2167
  state?: string;
1795
2168
  scopes?: string[];
1796
2169
  }): Promise<Session>;
2170
+ /**
2171
+ * Retrieves configured default resource scopes for a provider.
2172
+ *
2173
+ * @param provider - Provider name (e.g. 'github', 'google')
2174
+ * @returns Array of configured resource scopes, or undefined if not configured
2175
+ */
2176
+ getResourceScopes(provider: ConfiguredProviderKey<TProviders> | string): string[] | undefined;
2177
+ /**
2178
+ * Returns the resolved session cookie name.
2179
+ * Dynamically reflects any changes to the active identity provider.
2180
+ *
2181
+ * @param req - Optional request object for multi-tenant request-scoped cookie resolution
2182
+ * @returns Resolved session cookie name
2183
+ */
2184
+ getSessionCookieName(req?: unknown): string;
2185
+ /**
2186
+ * Sets or updates the session cookie name or dynamic resolver on this instance.
2187
+ *
2188
+ * @param resolver - Static cookie name or dynamic resolver function
2189
+ */
2190
+ setSessionCookieName(resolver: SessionCookieResolver<Lixa<TProviders>>): void;
1797
2191
  /**
1798
2192
  * Retrieves a connected resource for a specific User ID / Email directly (independent of session IDs).
1799
2193
  * Automatically refreshes expired access tokens if a refresh token is present.
@@ -1849,46 +2243,60 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1849
2243
  deleteSession(sessionId: string): Promise<void>;
1850
2244
  private exchangeCodeForToken;
1851
2245
  /**
1852
- * Checks if credentials (username and password) authentication is configured and enabled.
2246
+ * Checks if an identity provider (Self-Managed Database, AWS Cognito, Auth0, Okta, etc.) is configured.
1853
2247
  *
1854
- * @returns True if credentials authentication is available
2248
+ * @returns True if identity provider is configured and available
2249
+ */
2250
+ isIdentityEnabled(): boolean;
2251
+ /**
2252
+ * Checks if credentials / identity authentication is configured and enabled.
2253
+ *
2254
+ * @returns True if credentials / identity authentication is available
1855
2255
  */
1856
2256
  isCredentialsEnabled(): boolean;
1857
2257
  /**
1858
- * Returns the underlying CredentialsManager instance if configured.
2258
+ * Returns the configured IdentityProvider instance.
2259
+ */
2260
+ getIdentityProvider(): IIdentityProvider | undefined;
2261
+ /**
2262
+ * Dynamically sets or updates the active identity provider (e.g. SelfManaged, Cognito, Auth0, Okta).
2263
+ *
2264
+ * @param provider - Identity provider instance or undefined to disable
2265
+ */
2266
+ setIdentityProvider(provider?: IIdentityProvider): void;
2267
+ /**
2268
+ * Returns the underlying CredentialsManager instance if using Self-Managed identity.
1859
2269
  */
1860
2270
  getCredentialsManager(): CredentialsManager | undefined;
1861
2271
  /**
1862
- * Registers a new user with username/email and password.
1863
- * Automatically enforces password policy, hashes password with Scrypt/configured hasher,
1864
- * stores credentials, and creates a session (unless autoCreateSessionOnSignUp is false).
2272
+ * Registers a new user with the configured identity provider (Self-Managed DB, Cognito, Auth0, Okta).
2273
+ * Automatically creates an active session unless autoCreateSessionOnSignUp is explicitly set to false.
1865
2274
  *
1866
2275
  * @param params - Registration parameters (identifier, password, email, username, metadata)
1867
- * @returns Created user (without password hash) and optional active session
2276
+ * @returns Created user identity and optional active session
1868
2277
  * @throws WeakPasswordError if password does not meet policy requirements
1869
2278
  * @throws UserAlreadyExistsError if identifier is already registered
1870
- * @throws CredentialsNotConfiguredError if credentials auth is not configured
2279
+ * @throws IdentityNotConfiguredError if identity authentication is not configured
1871
2280
  */
1872
2281
  signUp(params: SignUpParams): Promise<SignUpResult>;
1873
2282
  /**
1874
- * Authenticates a user with username/email and password.
1875
- * Performs constant-time verification with timing attack mitigation, and creates an active session.
1876
- * If account linking is configured with AUTO_LINK_BY_VERIFIED_EMAIL, merges with existing session.
2283
+ * Authenticates a user with credentials via the configured identity provider (Self-Managed DB, Cognito, Auth0, Okta).
2284
+ * Creates an active session and automatically links with existing sessions when AUTO_LINK_BY_VERIFIED_EMAIL is configured.
1877
2285
  *
1878
2286
  * @param params - Sign-in parameters (identifier, password)
1879
2287
  * @returns Authenticated user, session ID, and session object
1880
2288
  * @throws InvalidCredentialsError if authentication fails
1881
- * @throws CredentialsNotConfiguredError if credentials auth is not configured
2289
+ * @throws IdentityNotConfiguredError if identity authentication is not configured
1882
2290
  */
1883
2291
  signIn(params: SignInParams): Promise<SignInResult>;
1884
2292
  /**
1885
2293
  * Verifies username/email and password credentials without generating a session.
1886
2294
  *
1887
2295
  * @param params - Verification parameters (identifier, password)
1888
- * @returns User credentials (without password hash) or null if invalid
1889
- * @throws CredentialsNotConfiguredError if credentials auth is not configured
2296
+ * @returns User credentials/identity or null if invalid
2297
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1890
2298
  */
1891
- verifyCredentials(params: VerifyCredentialsParams): Promise<Omit<UserCredentials, "passwordHash"> | null>;
2299
+ verifyCredentials(params: VerifyCredentialsParams): Promise<UserIdentity | null>;
1892
2300
  /**
1893
2301
  * Updates a user's password after verifying the current password and enforcing policy on the new password.
1894
2302
  *
@@ -1897,9 +2305,63 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1897
2305
  * @throws UserNotFoundError if user is not found
1898
2306
  * @throws InvalidCredentialsError if current password is incorrect
1899
2307
  * @throws WeakPasswordError if new password does not meet policy requirements
1900
- * @throws CredentialsNotConfiguredError if credentials auth is not configured
2308
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1901
2309
  */
1902
2310
  changePassword(params: ChangePasswordParams): Promise<boolean>;
2311
+ /**
2312
+ * Initiates a password reset (forgot password flow) through the configured identity provider.
2313
+ *
2314
+ * @param params - Forgot password parameters (identifier, optional metadata)
2315
+ * @returns ForgotPasswordResult indicating status and delivery medium (email/SMS)
2316
+ * @throws IdentityNotConfiguredError if identity auth is not configured
2317
+ */
2318
+ forgotPassword(params: ForgotPasswordParams): Promise<ForgotPasswordResult>;
2319
+ /**
2320
+ * Confirms a password reset using a verification code / token and sets the new password.
2321
+ *
2322
+ * @param params - Verification code, identifier, and new password
2323
+ * @returns True if password reset was successfully confirmed
2324
+ * @throws IdentityNotConfiguredError if identity auth is not configured
2325
+ */
2326
+ confirmPasswordReset(params: ConfirmPasswordResetParams): Promise<boolean>;
2327
+ /**
2328
+ * Confirms user account registration using a verification code.
2329
+ *
2330
+ * @param params - Verification parameters including identifier and confirmationCode
2331
+ * @returns True if confirmation was successful
2332
+ * @throws IdentityNotConfiguredError if identity auth is not configured
2333
+ * @throws IdentityProviderError if identity provider does not support confirmation
2334
+ */
2335
+ confirmSignUp(params: ConfirmSignUpParams): Promise<boolean>;
2336
+ /**
2337
+ * Resends the sign up confirmation code to the user.
2338
+ *
2339
+ * @param params - Resend parameters including user identifier
2340
+ * @returns Details about the code delivery (medium, destination)
2341
+ * @throws IdentityNotConfiguredError if identity auth is not configured
2342
+ * @throws IdentityProviderError if identity provider does not support resending codes
2343
+ */
2344
+ resendConfirmationCode(params: ResendConfirmationCodeParams): Promise<ResendConfirmationCodeResult>;
2345
+ /**
2346
+ * Retrieves a user by their unique ID from the configured identity provider.
2347
+ *
2348
+ * @param id - Unique user ID
2349
+ * @returns UserIdentity or null if not found
2350
+ */
2351
+ getUserById(id: string): Promise<UserIdentity | null>;
2352
+ /**
2353
+ * Retrieves a user by their identifier (username or email) from the configured identity provider.
2354
+ *
2355
+ * @param identifier - Username or email string
2356
+ * @returns UserIdentity or null if not found
2357
+ */
2358
+ getUserByIdentifier(identifier: string): Promise<UserIdentity | null>;
2359
+ /**
2360
+ * Deletes a user account from the configured identity provider.
2361
+ *
2362
+ * @param id - Unique user ID
2363
+ */
2364
+ deleteUser(id: string): Promise<void>;
1903
2365
  private findProviderByType;
1904
2366
  }
1905
2367
 
@@ -2115,6 +2577,25 @@ declare class WeakPasswordError extends LixaError {
2115
2577
  declare class CredentialsNotConfiguredError extends LixaError {
2116
2578
  constructor(message?: string, details?: Record<string, unknown>);
2117
2579
  }
2580
+ /**
2581
+ * Thrown when an identity provider operation fails with an upstream provider error.
2582
+ *
2583
+ * @public
2584
+ */
2585
+ declare class IdentityProviderError extends LixaError {
2586
+ readonly provider: string | undefined;
2587
+ readonly statusCode: number | undefined;
2588
+ constructor(message: string, provider?: string, statusCode?: number, details?: Record<string, unknown>);
2589
+ }
2590
+ /**
2591
+ * Thrown when identity operations (signUp, signIn, etc.) are invoked on a Lixa instance
2592
+ * where neither identity nor credentials authentication is enabled.
2593
+ *
2594
+ * @public
2595
+ */
2596
+ declare class IdentityNotConfiguredError extends CredentialsNotConfiguredError {
2597
+ constructor(message?: string, details?: Record<string, unknown>);
2598
+ }
2118
2599
 
2119
2600
  /**
2120
2601
  * Sensible default cookie configuration options.
@@ -2258,31 +2739,48 @@ declare function createStateCookie(state: string, options?: CookieOptions): Cook
2258
2739
  */
2259
2740
  declare function clearStateCookie(options?: CookieOptions): CookiePayload;
2260
2741
 
2261
- type index_ChangePasswordParams = ChangePasswordParams;
2262
- type index_CredentialsConfig = CredentialsConfig;
2263
- type index_CredentialsManager = CredentialsManager;
2264
- declare const index_CredentialsManager: typeof CredentialsManager;
2265
- type index_CredentialsStorage = CredentialsStorage;
2266
- type index_IPasswordHasher = IPasswordHasher;
2267
- type index_LocalCredentialsStorage = LocalCredentialsStorage;
2268
- declare const index_LocalCredentialsStorage: typeof LocalCredentialsStorage;
2269
- type index_PasswordPolicyConfig = PasswordPolicyConfig;
2270
- type index_PasswordPolicyResult = PasswordPolicyResult;
2271
- type index_Pbkdf2HasherOptions = Pbkdf2HasherOptions;
2272
- type index_Pbkdf2PasswordHasher = Pbkdf2PasswordHasher;
2273
- declare const index_Pbkdf2PasswordHasher: typeof Pbkdf2PasswordHasher;
2274
- type index_ScryptHasherOptions = ScryptHasherOptions;
2275
- type index_ScryptPasswordHasher = ScryptPasswordHasher;
2276
- declare const index_ScryptPasswordHasher: typeof ScryptPasswordHasher;
2277
- type index_SignInParams = SignInParams;
2278
- type index_SignInResult<TSession = Session> = SignInResult<TSession>;
2279
- type index_SignUpParams = SignUpParams;
2280
- type index_SignUpResult<TSession = Session> = SignUpResult<TSession>;
2281
- type index_UserCredentials = UserCredentials;
2282
- type index_VerifyCredentialsParams = VerifyCredentialsParams;
2283
- declare const index_validatePasswordPolicy: typeof validatePasswordPolicy;
2742
+ type index$1_ChangePasswordParams = ChangePasswordParams;
2743
+ type index$1_CredentialsConfig = CredentialsConfig;
2744
+ type index$1_CredentialsManager = CredentialsManager;
2745
+ declare const index$1_CredentialsManager: typeof CredentialsManager;
2746
+ type index$1_CredentialsStorage = CredentialsStorage;
2747
+ type index$1_IPasswordHasher = IPasswordHasher;
2748
+ type index$1_LocalCredentialsStorage = LocalCredentialsStorage;
2749
+ declare const index$1_LocalCredentialsStorage: typeof LocalCredentialsStorage;
2750
+ type index$1_PasswordPolicyConfig = PasswordPolicyConfig;
2751
+ type index$1_PasswordPolicyResult = PasswordPolicyResult;
2752
+ type index$1_Pbkdf2HasherOptions = Pbkdf2HasherOptions;
2753
+ type index$1_Pbkdf2PasswordHasher = Pbkdf2PasswordHasher;
2754
+ declare const index$1_Pbkdf2PasswordHasher: typeof Pbkdf2PasswordHasher;
2755
+ type index$1_ScryptHasherOptions = ScryptHasherOptions;
2756
+ type index$1_ScryptPasswordHasher = ScryptPasswordHasher;
2757
+ declare const index$1_ScryptPasswordHasher: typeof ScryptPasswordHasher;
2758
+ type index$1_SignInParams = SignInParams;
2759
+ type index$1_SignInResult<TSession = Session, TUser = UserIdentity> = SignInResult<TSession, TUser>;
2760
+ type index$1_SignUpParams = SignUpParams;
2761
+ type index$1_SignUpResult<TSession = Session, TUser = UserIdentity> = SignUpResult<TSession, TUser>;
2762
+ type index$1_UserCredentials = UserCredentials;
2763
+ type index$1_VerifyCredentialsParams = VerifyCredentialsParams;
2764
+ declare const index$1_validatePasswordPolicy: typeof validatePasswordPolicy;
2765
+ declare namespace index$1 {
2766
+ export { type index$1_ChangePasswordParams as ChangePasswordParams, type index$1_CredentialsConfig as CredentialsConfig, index$1_CredentialsManager as CredentialsManager, type index$1_CredentialsStorage as CredentialsStorage, type index$1_IPasswordHasher as IPasswordHasher, index$1_LocalCredentialsStorage as LocalCredentialsStorage, type index$1_PasswordPolicyConfig as PasswordPolicyConfig, type index$1_PasswordPolicyResult as PasswordPolicyResult, type index$1_Pbkdf2HasherOptions as Pbkdf2HasherOptions, index$1_Pbkdf2PasswordHasher as Pbkdf2PasswordHasher, type index$1_ScryptHasherOptions as ScryptHasherOptions, index$1_ScryptPasswordHasher as ScryptPasswordHasher, type index$1_SignInParams as SignInParams, type index$1_SignInResult as SignInResult, type index$1_SignUpParams as SignUpParams, type index$1_SignUpResult as SignUpResult, type index$1_UserCredentials as UserCredentials, type index$1_VerifyCredentialsParams as VerifyCredentialsParams, index$1_validatePasswordPolicy as validatePasswordPolicy };
2767
+ }
2768
+
2769
+ type index_ConfirmPasswordResetParams = ConfirmPasswordResetParams;
2770
+ type index_ConfirmSignUpParams = ConfirmSignUpParams;
2771
+ type index_ForgotPasswordParams = ForgotPasswordParams;
2772
+ type index_ForgotPasswordResult = ForgotPasswordResult;
2773
+ type index_IIdentityProvider = IIdentityProvider;
2774
+ type index_IdentityAuthResult = IdentityAuthResult;
2775
+ type index_IdentityConfig = IdentityConfig;
2776
+ type index_IdentityTokens = IdentityTokens;
2777
+ type index_ResendConfirmationCodeParams = ResendConfirmationCodeParams;
2778
+ type index_ResendConfirmationCodeResult = ResendConfirmationCodeResult;
2779
+ type index_SelfManagedIdentityProvider = SelfManagedIdentityProvider;
2780
+ declare const index_SelfManagedIdentityProvider: typeof SelfManagedIdentityProvider;
2781
+ type index_UserIdentity = UserIdentity;
2284
2782
  declare namespace index {
2285
- export { type index_ChangePasswordParams as ChangePasswordParams, type index_CredentialsConfig as CredentialsConfig, index_CredentialsManager as CredentialsManager, type index_CredentialsStorage as CredentialsStorage, type index_IPasswordHasher as IPasswordHasher, index_LocalCredentialsStorage as LocalCredentialsStorage, type index_PasswordPolicyConfig as PasswordPolicyConfig, type index_PasswordPolicyResult as PasswordPolicyResult, type index_Pbkdf2HasherOptions as Pbkdf2HasherOptions, index_Pbkdf2PasswordHasher as Pbkdf2PasswordHasher, type index_ScryptHasherOptions as ScryptHasherOptions, index_ScryptPasswordHasher as ScryptPasswordHasher, type index_SignInParams as SignInParams, type index_SignInResult as SignInResult, type index_SignUpParams as SignUpParams, type index_SignUpResult as SignUpResult, type index_UserCredentials as UserCredentials, type index_VerifyCredentialsParams as VerifyCredentialsParams, index_validatePasswordPolicy as validatePasswordPolicy };
2783
+ export { type index_ConfirmPasswordResetParams as ConfirmPasswordResetParams, type index_ConfirmSignUpParams as ConfirmSignUpParams, type index_ForgotPasswordParams as ForgotPasswordParams, type index_ForgotPasswordResult as ForgotPasswordResult, type index_IIdentityProvider as IIdentityProvider, type index_IdentityAuthResult as IdentityAuthResult, type index_IdentityConfig as IdentityConfig, type index_IdentityTokens as IdentityTokens, type index_ResendConfirmationCodeParams as ResendConfirmationCodeParams, type index_ResendConfirmationCodeResult as ResendConfirmationCodeResult, index_SelfManagedIdentityProvider as SelfManagedIdentityProvider, type index_UserIdentity as UserIdentity };
2286
2784
  }
2287
2785
 
2288
- export { type AccountLinkingConfig, type AccountLinkingMode, AccountLinkingStrategy, AccountUnlinkError, type ChangePasswordParams, type ConnectedResource, type CookieOptions, type CookiePayload, type CredentialsConfig, CredentialsManager, CredentialsNotConfiguredError, type CredentialsStorage, DEFAULT_SESSION_COOKIE_NAME, DEFAULT_SESSION_MAX_AGE_SECONDS, DEFAULT_STATE_COOKIE_NAME, DEFAULT_STATE_MAX_AGE_SECONDS, EmailNotVerifiedError, type IPasswordHasher, type IProvider, InvalidCredentialsError, InvalidOAuthCallbackError, InvalidProviderConfigError, InvalidStateError, Lixa, type LixaConfig, LixaError, type LixaLogger, LocalCredentialsStorage, type LogContext, type LogLevel, type OAuthTokenResponse, type PasswordPolicyConfig, type PasswordPolicyResult, type Pbkdf2HasherOptions, Pbkdf2PasswordHasher, type ProviderConfig, type ProviderMetadata, ProviderNotConfiguredError, RefreshTokenError, type ResourceHandler, type ResourceStorage, type SafeLixaConfig, type ScryptHasherOptions, ScryptPasswordHasher, type Session, type SessionHandler, SessionNotFoundError, type SessionStorage, type SignInParams, type SignInResult, type SignUpParams, type SignUpResult, type StateData, type StateHandler, type StateStorage, TokenExchangeError, UserAlreadyExistsError, type UserCredentials, type UserInfo, UserNotFoundError, type VerifyCredentialsParams, WeakPasswordError, clearSessionCookie, clearStateCookie, createSessionCookie, createStateCookie, index as credentials, decodeIdToken, determineProviderFromIssuer, extractUserInfo, fetchUserInfo, isProductionEnvironment, serializeCookie, validatePasswordPolicy };
2786
+ export { type AccountHandler, type AccountLinkingConfig, type AccountLinkingMode, AccountLinkingStrategy, type AccountStorage, AccountUnlinkError, type ChangePasswordParams, type ConfirmPasswordResetParams, type ConfirmSignUpParams, type ConnectedResource, type CookieOptions, type CookiePayload, type CredentialsConfig, CredentialsManager, CredentialsNotConfiguredError, type CredentialsStorage, DEFAULT_SESSION_COOKIE_NAME, DEFAULT_SESSION_MAX_AGE_SECONDS, DEFAULT_STATE_COOKIE_NAME, DEFAULT_STATE_MAX_AGE_SECONDS, EmailNotVerifiedError, type ForgotPasswordParams, type ForgotPasswordResult, type IIdentityProvider, type IPasswordHasher, type IProvider, type IdentityAuthResult, type IdentityConfig, IdentityNotConfiguredError, IdentityProviderError, type IdentityTokens, InvalidCredentialsError, InvalidOAuthCallbackError, InvalidProviderConfigError, InvalidStateError, type LinkedAccount, Lixa, type LixaConfig, type LixaCookieContext, LixaError, type LixaLogger, LocalCredentialsStorage, type LogContext, type LogLevel, type OAuthTokenResponse, type PasswordPolicyConfig, type PasswordPolicyResult, type Pbkdf2HasherOptions, Pbkdf2PasswordHasher, type ProviderConfig, type ProviderMetadata, ProviderNotConfiguredError, RefreshTokenError, type ResendConfirmationCodeParams, type ResendConfirmationCodeResult, type ResourceHandler, type ResourceStorage, type SafeLixaConfig, type ScryptHasherOptions, ScryptPasswordHasher, SelfManagedIdentityProvider, type Session, type SessionCookieResolver, type SessionHandler, SessionNotFoundError, type SessionStorage, type SignInParams, type SignInResult, type SignUpParams, type SignUpResult, type StateData, type StateHandler, type StateStorage, TokenExchangeError, UserAlreadyExistsError, type UserCredentials, type UserIdentity, type UserInfo, UserNotFoundError, type VerifyCredentialsParams, WeakPasswordError, clearSessionCookie, clearStateCookie, createSessionCookie, createStateCookie, index$1 as credentials, decodeIdToken, determineProviderFromIssuer, extractUserInfo, fetchUserInfo, index as identity, isProductionEnvironment, serializeCookie, validatePasswordPolicy };