@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.
@@ -16,6 +16,15 @@
16
16
  * @packageDocumentation
17
17
  */
18
18
 
19
+ /**
20
+ * Account handler configuration.
21
+ *
22
+ * @public
23
+ */
24
+ export declare interface AccountHandler {
25
+ accountStorage?: AccountStorage;
26
+ }
27
+
19
28
  /**
20
29
  * Account linking settings for Lixa.
21
30
  *
@@ -123,6 +132,18 @@ export declare enum AccountLinkingStrategy {
123
132
  ISOLATED = "ISOLATED"
124
133
  }
125
134
 
135
+ /**
136
+ * Interface for persistent linked account storage across user sessions.
137
+ *
138
+ * @public
139
+ */
140
+ export declare interface AccountStorage {
141
+ saveAccount(userId: string, provider: string, account: LinkedAccount): Promise<void>;
142
+ getAccount(userId: string, provider: string): Promise<LinkedAccount | null>;
143
+ getUserAccounts(userId: string): Promise<Record<string, LinkedAccount>>;
144
+ deleteAccount(userId: string, provider: string): Promise<void>;
145
+ }
146
+
126
147
  /**
127
148
  * Thrown when unlinking an account violates security constraints (e.g. unlinking the only login provider).
128
149
  *
@@ -179,7 +200,33 @@ export declare function clearStateCookie(options?: CookieOptions): CookiePayload
179
200
  /**
180
201
  * Type representing the keys of configured providers
181
202
  */
182
- declare type ConfiguredProviderKey<T extends LixaConfig<Record<string, ProviderConfig>>> = keyof T['providers'];
203
+ declare type ConfiguredProviderKey<TProviders extends Record<string, ProviderConfig>> = keyof TProviders & string;
204
+
205
+ /**
206
+ * Parameters for confirming a password reset with a confirmation code or token.
207
+ *
208
+ * @public
209
+ */
210
+ export declare interface ConfirmPasswordResetParams {
211
+ /** Username or email of the account */
212
+ identifier: string;
213
+ /** Verification code (e.g. 6-digit OTP from email/SMS) or reset token */
214
+ confirmationCode: string;
215
+ /** New plaintext password */
216
+ newPassword: string;
217
+ }
218
+
219
+ /**
220
+ * Parameters for confirming user registration with a verification code.
221
+ *
222
+ * @public
223
+ */
224
+ export declare interface ConfirmSignUpParams {
225
+ /** Username or email of the account to confirm */
226
+ identifier: string;
227
+ /** Verification code (e.g. 6-digit OTP from email/SMS) */
228
+ confirmationCode: string;
229
+ }
183
230
 
184
231
  /**
185
232
  * Represents a connected resource provider token (e.g. GitHub Repo access, Google Drive)
@@ -607,6 +654,200 @@ export declare function extractUserInfo(tokenData: OAuthTokenResponse, providerM
607
654
  */
608
655
  export declare function fetchUserInfo(accessToken: string, userInfoEndpoint: string): Promise<UserInfo>;
609
656
 
657
+ /**
658
+ * Parameters for requesting a password reset (forgot password).
659
+ *
660
+ * @public
661
+ */
662
+ export declare interface ForgotPasswordParams {
663
+ /** Username or email of the account requesting a password reset */
664
+ identifier: string;
665
+ /** Optional custom client metadata or redirect URL */
666
+ metadata?: Record<string, unknown> | undefined;
667
+ }
668
+
669
+ /**
670
+ * Result of a password reset request.
671
+ *
672
+ * @public
673
+ */
674
+ export declare interface ForgotPasswordResult {
675
+ /** Whether the password reset request was accepted */
676
+ success: boolean;
677
+ /** Delivery destination description (e.g. masked email: a***@example.com or phone) */
678
+ deliveryMedium?: string | undefined;
679
+ /** Optional message or status code from provider */
680
+ message?: string | undefined;
681
+ }
682
+
683
+ export declare namespace identity {
684
+ export {
685
+ UserIdentity,
686
+ IdentityTokens,
687
+ IdentityAuthResult,
688
+ ForgotPasswordParams,
689
+ ForgotPasswordResult,
690
+ ConfirmPasswordResetParams,
691
+ ConfirmSignUpParams,
692
+ ResendConfirmationCodeParams,
693
+ ResendConfirmationCodeResult,
694
+ IIdentityProvider,
695
+ IdentityConfig,
696
+ SelfManagedIdentityProvider
697
+ }
698
+ }
699
+
700
+ /**
701
+ * Result of user authentication through an identity provider.
702
+ *
703
+ * @public
704
+ */
705
+ export declare interface IdentityAuthResult {
706
+ /** Authenticated user profile */
707
+ user: UserIdentity;
708
+ /** Optional tokens issued by the identity provider */
709
+ tokens?: IdentityTokens | undefined;
710
+ }
711
+
712
+ /**
713
+ * Configuration options for Identity Providers in LixaConfig.
714
+ *
715
+ * @public
716
+ */
717
+ export declare type IdentityConfig = IIdentityProvider | ({
718
+ provider?: "self-managed";
719
+ } & CredentialsConfig);
720
+
721
+ /**
722
+ * Thrown when identity operations (signUp, signIn, etc.) are invoked on a Lixa instance
723
+ * where neither identity nor credentials authentication is enabled.
724
+ *
725
+ * @public
726
+ */
727
+ export declare class IdentityNotConfiguredError extends CredentialsNotConfiguredError {
728
+ constructor(message?: string, details?: Record<string, unknown>);
729
+ }
730
+
731
+ /**
732
+ * Thrown when an identity provider operation fails with an upstream provider error.
733
+ *
734
+ * @public
735
+ */
736
+ export declare class IdentityProviderError extends LixaError {
737
+ readonly provider: string | undefined;
738
+ readonly statusCode: number | undefined;
739
+ constructor(message: string, provider?: string, statusCode?: number, details?: Record<string, unknown>);
740
+ }
741
+
742
+ /**
743
+ * Standardized token response from an identity provider.
744
+ *
745
+ * @public
746
+ */
747
+ export declare interface IdentityTokens {
748
+ /** OAuth / IdP Access Token (JWT or opaque token) */
749
+ accessToken?: string | undefined;
750
+ /** OpenID Connect ID Token containing user claims */
751
+ idToken?: string | undefined;
752
+ /** Refresh token for renewing expired credentials */
753
+ refreshToken?: string | undefined;
754
+ /** Token type (usually "Bearer") */
755
+ tokenType?: string | undefined;
756
+ /** Token expiration time in seconds */
757
+ expiresIn?: number | undefined;
758
+ /** Raw response object returned directly by the provider */
759
+ raw?: Record<string, unknown> | undefined;
760
+ }
761
+
762
+ /**
763
+ * Unified interface for Identity Providers in Lixa.
764
+ *
765
+ * @remarks
766
+ * Implement this interface to create custom identity providers (e.g. Supabase Auth,
767
+ * Firebase Auth, Keycloak, or proprietary enterprise directories).
768
+ *
769
+ * Built-in extensions for AWS Cognito, Auth0, and Okta are available in `@vunexa/lixa-extensions`.
770
+ *
771
+ * @public
772
+ */
773
+ export declare interface IIdentityProvider {
774
+ /**
775
+ * Unique name of the identity provider.
776
+ * Examples: 'self-managed', 'cognito', 'auth0', 'okta'
777
+ */
778
+ readonly name: string;
779
+ /**
780
+ * Registers a new user with the identity provider.
781
+ *
782
+ * @param params - User registration details (identifier, password, email, username, metadata)
783
+ * @returns Created user identity
784
+ */
785
+ signUp(params: SignUpParams): Promise<UserIdentity>;
786
+ /**
787
+ * Authenticates a user with credentials.
788
+ *
789
+ * @param params - Sign in credentials (identifier, password)
790
+ * @returns Authenticated user identity and optional provider tokens
791
+ */
792
+ signIn(params: SignInParams): Promise<IdentityAuthResult>;
793
+ /**
794
+ * Verifies credentials without necessarily creating a full session.
795
+ *
796
+ * @param params - Verification parameters
797
+ * @returns User identity if credentials are valid, null otherwise
798
+ */
799
+ verifyCredentials?(params: VerifyCredentialsParams): Promise<UserIdentity | null>;
800
+ /**
801
+ * Changes a user's password.
802
+ *
803
+ * @param params - Old password, new password, and user identifier
804
+ * @returns True if password was successfully updated
805
+ */
806
+ changePassword?(params: ChangePasswordParams): Promise<boolean>;
807
+ /**
808
+ * Requests a password reset (forgot password flow).
809
+ *
810
+ * @param params - Forgot password parameters
811
+ */
812
+ forgotPassword?(params: ForgotPasswordParams): Promise<ForgotPasswordResult>;
813
+ /**
814
+ * Confirms password reset with verification code and new password.
815
+ *
816
+ * @param params - Confirm password reset parameters
817
+ */
818
+ confirmPasswordReset?(params: ConfirmPasswordResetParams): Promise<boolean>;
819
+ /**
820
+ * Confirms user registration using a verification code.
821
+ *
822
+ * @param params - Confirm sign up parameters
823
+ */
824
+ confirmSignUp?(params: ConfirmSignUpParams): Promise<boolean>;
825
+ /**
826
+ * Resends the sign up confirmation code.
827
+ *
828
+ * @param params - Resend confirmation code parameters
829
+ */
830
+ resendConfirmationCode?(params: ResendConfirmationCodeParams): Promise<ResendConfirmationCodeResult>;
831
+ /**
832
+ * Retrieves a user by their unique ID.
833
+ *
834
+ * @param id - Unique user ID
835
+ */
836
+ getUserById?(id: string): Promise<UserIdentity | null>;
837
+ /**
838
+ * Retrieves a user by their identifier (email or username).
839
+ *
840
+ * @param identifier - Username or email string
841
+ */
842
+ getUserByIdentifier?(identifier: string): Promise<UserIdentity | null>;
843
+ /**
844
+ * Deletes a user account.
845
+ *
846
+ * @param id - Unique user ID
847
+ */
848
+ deleteUser?(id: string): Promise<void>;
849
+ }
850
+
610
851
  /**
611
852
  * Thrown when user credentials (username/email and password) are invalid during authentication.
612
853
  *
@@ -809,6 +1050,10 @@ export declare interface IProvider {
809
1050
  * @example ['openid', 'email', 'profile'] or ['read:user', 'user:email']
810
1051
  */
811
1052
  authScopes?: string[];
1053
+ /**
1054
+ * Default OAuth scopes requested when not explicitly specified in ProviderConfig.
1055
+ */
1056
+ defaultScopes?: string[];
812
1057
  }
813
1058
 
814
1059
  /**
@@ -822,7 +1067,7 @@ export declare function isProductionEnvironment(): boolean;
822
1067
  *
823
1068
  * @public
824
1069
  */
825
- declare interface LinkedAccount {
1070
+ export declare interface LinkedAccount {
826
1071
  /** The provider identifier (e.g. 'github', 'google') */
827
1072
  provider: string;
828
1073
  /** Provider user ID if available */
@@ -889,20 +1134,25 @@ declare interface LinkedAccount {
889
1134
  *
890
1135
  * @public
891
1136
  */
892
- export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> = LixaConfig> {
1137
+ export declare class Lixa<TProviders extends Record<string, ProviderConfig> = Record<string, ProviderConfig>> {
893
1138
  private static DEFAULT_PROVIDERS;
894
1139
  private static CONFIGURED_PROVIDERS;
895
1140
  private localStateHandler;
896
1141
  private localSessionHandler;
897
1142
  private localResourceHandler;
1143
+ private localAccountHandler;
898
1144
  private userResourceStore;
1145
+ private userAccountStore;
899
1146
  private refreshMutexes;
1147
+ private identityProvider?;
900
1148
  private credentialsManager?;
901
1149
  private config;
902
1150
  private stateHandler;
903
1151
  private sessionHandler;
904
1152
  private resourceHandler;
1153
+ private accountHandler;
905
1154
  private debug;
1155
+ private sessionCookieResolver?;
906
1156
  /**
907
1157
  * Creates a new Lixa instance with the provided configuration.
908
1158
  *
@@ -916,7 +1166,7 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
916
1166
  * @throws Error when provider implementation is missing required properties
917
1167
  * @throws Error when provider is not available and no inline implementation is provided
918
1168
  */
919
- constructor(config: TConfig);
1169
+ constructor(config: LixaConfig<TProviders>);
920
1170
  /**
921
1171
  * Validates that a provider configuration has all required credentials.
922
1172
  *
@@ -957,7 +1207,7 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
957
1207
  * }
958
1208
  * ```
959
1209
  */
960
- isProviderConfigured<T extends string>(provider: T): provider is T & ConfiguredProviderKey<TConfig>;
1210
+ isProviderConfigured<T extends string>(provider: T): provider is T & ConfiguredProviderKey<TProviders>;
961
1211
  /**
962
1212
  * Gets a provider implementation by name.
963
1213
  * Resolution priority: inline custom provider \> default providers \> legacy registry
@@ -1138,7 +1388,7 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
1138
1388
  * res.redirect(authUrl);
1139
1389
  * ```
1140
1390
  */
1141
- getAuthUrl(provider: ConfiguredProviderKey<TConfig> | string, state?: string): Promise<string>;
1391
+ getAuthUrl(provider: ConfiguredProviderKey<TProviders> | string, state?: string): Promise<string>;
1142
1392
  /**
1143
1393
  * Restricts primary authentication scopes strictly to AuthN identity scopes unless allowNonAuthScopes is true.
1144
1394
  */
@@ -1162,10 +1412,11 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
1162
1412
  * });
1163
1413
  * ```
1164
1414
  */
1165
- handleCallback({ provider, code, state, }: {
1166
- provider: ConfiguredProviderKey<TConfig> | string;
1415
+ handleCallback({ provider, code, state, sessionId, }: {
1416
+ provider: ConfiguredProviderKey<TProviders> | string;
1167
1417
  code: string;
1168
1418
  state?: string;
1419
+ sessionId?: string;
1169
1420
  }): Promise<string>;
1170
1421
  /**
1171
1422
  * Explicitly link a new OAuth provider account to an active session.
@@ -1175,7 +1426,7 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
1175
1426
  */
1176
1427
  linkAccount(params: {
1177
1428
  sessionId: string;
1178
- provider: ConfiguredProviderKey<TConfig> | string;
1429
+ provider: ConfiguredProviderKey<TProviders> | string;
1179
1430
  code: string;
1180
1431
  state?: string;
1181
1432
  }): Promise<string>;
@@ -1200,8 +1451,8 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
1200
1451
  */
1201
1452
  getResourceAuthUrl(params: {
1202
1453
  sessionId: string;
1203
- provider: ConfiguredProviderKey<TConfig> | string;
1204
- scopes: string[];
1454
+ provider: ConfiguredProviderKey<TProviders> | string;
1455
+ scopes?: string[];
1205
1456
  state?: string;
1206
1457
  prompt?: string;
1207
1458
  extraConfig?: Record<string, string>;
@@ -1212,11 +1463,32 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
1212
1463
  */
1213
1464
  handleResourceCallback(params: {
1214
1465
  sessionId: string;
1215
- provider: ConfiguredProviderKey<TConfig> | string;
1466
+ provider: ConfiguredProviderKey<TProviders> | string;
1216
1467
  code: string;
1217
1468
  state?: string;
1218
1469
  scopes?: string[];
1219
1470
  }): Promise<Session>;
1471
+ /**
1472
+ * Retrieves configured default resource scopes for a provider.
1473
+ *
1474
+ * @param provider - Provider name (e.g. 'github', 'google')
1475
+ * @returns Array of configured resource scopes, or undefined if not configured
1476
+ */
1477
+ getResourceScopes(provider: ConfiguredProviderKey<TProviders> | string): string[] | undefined;
1478
+ /**
1479
+ * Returns the resolved session cookie name.
1480
+ * Dynamically reflects any changes to the active identity provider.
1481
+ *
1482
+ * @param req - Optional request object for multi-tenant request-scoped cookie resolution
1483
+ * @returns Resolved session cookie name
1484
+ */
1485
+ getSessionCookieName(req?: unknown): string;
1486
+ /**
1487
+ * Sets or updates the session cookie name or dynamic resolver on this instance.
1488
+ *
1489
+ * @param resolver - Static cookie name or dynamic resolver function
1490
+ */
1491
+ setSessionCookieName(resolver: SessionCookieResolver<Lixa<TProviders>>): void;
1220
1492
  /**
1221
1493
  * Retrieves a connected resource for a specific User ID / Email directly (independent of session IDs).
1222
1494
  * Automatically refreshes expired access tokens if a refresh token is present.
@@ -1272,46 +1544,60 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
1272
1544
  deleteSession(sessionId: string): Promise<void>;
1273
1545
  private exchangeCodeForToken;
1274
1546
  /**
1275
- * Checks if credentials (username and password) authentication is configured and enabled.
1547
+ * Checks if an identity provider (Self-Managed Database, AWS Cognito, Auth0, Okta, etc.) is configured.
1276
1548
  *
1277
- * @returns True if credentials authentication is available
1549
+ * @returns True if identity provider is configured and available
1550
+ */
1551
+ isIdentityEnabled(): boolean;
1552
+ /**
1553
+ * Checks if credentials / identity authentication is configured and enabled.
1554
+ *
1555
+ * @returns True if credentials / identity authentication is available
1278
1556
  */
1279
1557
  isCredentialsEnabled(): boolean;
1280
1558
  /**
1281
- * Returns the underlying CredentialsManager instance if configured.
1559
+ * Returns the configured IdentityProvider instance.
1560
+ */
1561
+ getIdentityProvider(): IIdentityProvider | undefined;
1562
+ /**
1563
+ * Dynamically sets or updates the active identity provider (e.g. SelfManaged, Cognito, Auth0, Okta).
1564
+ *
1565
+ * @param provider - Identity provider instance or undefined to disable
1566
+ */
1567
+ setIdentityProvider(provider?: IIdentityProvider): void;
1568
+ /**
1569
+ * Returns the underlying CredentialsManager instance if using Self-Managed identity.
1282
1570
  */
1283
1571
  getCredentialsManager(): CredentialsManager | undefined;
1284
1572
  /**
1285
- * Registers a new user with username/email and password.
1286
- * Automatically enforces password policy, hashes password with Scrypt/configured hasher,
1287
- * stores credentials, and creates a session (unless autoCreateSessionOnSignUp is false).
1573
+ * Registers a new user with the configured identity provider (Self-Managed DB, Cognito, Auth0, Okta).
1574
+ * Automatically creates an active session unless autoCreateSessionOnSignUp is explicitly set to false.
1288
1575
  *
1289
1576
  * @param params - Registration parameters (identifier, password, email, username, metadata)
1290
- * @returns Created user (without password hash) and optional active session
1577
+ * @returns Created user identity and optional active session
1291
1578
  * @throws WeakPasswordError if password does not meet policy requirements
1292
1579
  * @throws UserAlreadyExistsError if identifier is already registered
1293
- * @throws CredentialsNotConfiguredError if credentials auth is not configured
1580
+ * @throws IdentityNotConfiguredError if identity authentication is not configured
1294
1581
  */
1295
1582
  signUp(params: SignUpParams): Promise<SignUpResult>;
1296
1583
  /**
1297
- * Authenticates a user with username/email and password.
1298
- * Performs constant-time verification with timing attack mitigation, and creates an active session.
1299
- * If account linking is configured with AUTO_LINK_BY_VERIFIED_EMAIL, merges with existing session.
1584
+ * Authenticates a user with credentials via the configured identity provider (Self-Managed DB, Cognito, Auth0, Okta).
1585
+ * Creates an active session and automatically links with existing sessions when AUTO_LINK_BY_VERIFIED_EMAIL is configured.
1300
1586
  *
1301
1587
  * @param params - Sign-in parameters (identifier, password)
1302
1588
  * @returns Authenticated user, session ID, and session object
1303
1589
  * @throws InvalidCredentialsError if authentication fails
1304
- * @throws CredentialsNotConfiguredError if credentials auth is not configured
1590
+ * @throws IdentityNotConfiguredError if identity authentication is not configured
1305
1591
  */
1306
1592
  signIn(params: SignInParams): Promise<SignInResult>;
1307
1593
  /**
1308
1594
  * Verifies username/email and password credentials without generating a session.
1309
1595
  *
1310
1596
  * @param params - Verification parameters (identifier, password)
1311
- * @returns User credentials (without password hash) or null if invalid
1312
- * @throws CredentialsNotConfiguredError if credentials auth is not configured
1597
+ * @returns User credentials/identity or null if invalid
1598
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1313
1599
  */
1314
- verifyCredentials(params: VerifyCredentialsParams): Promise<Omit<UserCredentials, "passwordHash"> | null>;
1600
+ verifyCredentials(params: VerifyCredentialsParams): Promise<UserIdentity | null>;
1315
1601
  /**
1316
1602
  * Updates a user's password after verifying the current password and enforcing policy on the new password.
1317
1603
  *
@@ -1320,9 +1606,63 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
1320
1606
  * @throws UserNotFoundError if user is not found
1321
1607
  * @throws InvalidCredentialsError if current password is incorrect
1322
1608
  * @throws WeakPasswordError if new password does not meet policy requirements
1323
- * @throws CredentialsNotConfiguredError if credentials auth is not configured
1609
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1324
1610
  */
1325
1611
  changePassword(params: ChangePasswordParams): Promise<boolean>;
1612
+ /**
1613
+ * Initiates a password reset (forgot password flow) through the configured identity provider.
1614
+ *
1615
+ * @param params - Forgot password parameters (identifier, optional metadata)
1616
+ * @returns ForgotPasswordResult indicating status and delivery medium (email/SMS)
1617
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1618
+ */
1619
+ forgotPassword(params: ForgotPasswordParams): Promise<ForgotPasswordResult>;
1620
+ /**
1621
+ * Confirms a password reset using a verification code / token and sets the new password.
1622
+ *
1623
+ * @param params - Verification code, identifier, and new password
1624
+ * @returns True if password reset was successfully confirmed
1625
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1626
+ */
1627
+ confirmPasswordReset(params: ConfirmPasswordResetParams): Promise<boolean>;
1628
+ /**
1629
+ * Confirms user account registration using a verification code.
1630
+ *
1631
+ * @param params - Verification parameters including identifier and confirmationCode
1632
+ * @returns True if confirmation was successful
1633
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1634
+ * @throws IdentityProviderError if identity provider does not support confirmation
1635
+ */
1636
+ confirmSignUp(params: ConfirmSignUpParams): Promise<boolean>;
1637
+ /**
1638
+ * Resends the sign up confirmation code to the user.
1639
+ *
1640
+ * @param params - Resend parameters including user identifier
1641
+ * @returns Details about the code delivery (medium, destination)
1642
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1643
+ * @throws IdentityProviderError if identity provider does not support resending codes
1644
+ */
1645
+ resendConfirmationCode(params: ResendConfirmationCodeParams): Promise<ResendConfirmationCodeResult>;
1646
+ /**
1647
+ * Retrieves a user by their unique ID from the configured identity provider.
1648
+ *
1649
+ * @param id - Unique user ID
1650
+ * @returns UserIdentity or null if not found
1651
+ */
1652
+ getUserById(id: string): Promise<UserIdentity | null>;
1653
+ /**
1654
+ * Retrieves a user by their identifier (username or email) from the configured identity provider.
1655
+ *
1656
+ * @param identifier - Username or email string
1657
+ * @returns UserIdentity or null if not found
1658
+ */
1659
+ getUserByIdentifier(identifier: string): Promise<UserIdentity | null>;
1660
+ /**
1661
+ * Deletes a user account from the configured identity provider.
1662
+ *
1663
+ * @param id - Unique user ID
1664
+ */
1665
+ deleteUser(id: string): Promise<void>;
1326
1666
  private findProviderByType;
1327
1667
  }
1328
1668
 
@@ -1334,18 +1674,50 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
1334
1674
  */
1335
1675
  export declare interface LixaConfig<TProviders extends Record<string, ProviderConfig> = Record<string, ProviderConfig>> {
1336
1676
  /**
1337
- * Map of provider names to their configurations.
1677
+ * Map of federated OAuth 2.0 / OIDC provider names to their configurations (Google, GitHub, etc.)
1678
+ * that federate with and work alongside the primary identityProvider.
1338
1679
  * Provider names will be available for autocomplete in getAuthUrl() and handleCallback().
1339
1680
  */
1681
+ federatedOAuthProviders?: TProviders;
1682
+ /**
1683
+ * Alias for {@link LixaConfig.federatedOAuthProviders}.
1684
+ */
1340
1685
  providers?: TProviders;
1686
+ /**
1687
+ * Primary Identity Provider configuration (Self-Managed Database, AWS Cognito, Auth0, Okta, or custom IIdentityProvider).
1688
+ *
1689
+ * @example
1690
+ * Self-managed with Prisma:
1691
+ * ```typescript
1692
+ * identityProvider: { storage: prismaAdapter.credentialsStorage }
1693
+ * ```
1694
+ *
1695
+ * @example
1696
+ * AWS Cognito:
1697
+ * ```typescript
1698
+ * identityProvider: new CognitoIdentityProvider({ userPoolId: '...', clientId: '...', region: 'us-east-1' })
1699
+ * ```
1700
+ */
1701
+ identityProvider?: IIdentityProvider | IdentityConfig;
1702
+ /**
1703
+ * Alias for {@link LixaConfig.identityProvider}.
1704
+ */
1705
+ identity?: IIdentityProvider | IdentityConfig;
1341
1706
  /**
1342
1707
  * Credentials (username and password) authentication configuration.
1708
+ * Automatically maps to a SelfManagedIdentityProvider.
1343
1709
  */
1344
1710
  credentials?: CredentialsConfig;
1711
+ /**
1712
+ * Unified database storage adapter (e.g. createPrismaAdapter or createDrizzleAdapter).
1713
+ * Automatically configures sessionHandler, stateHandler, and resourceHandler.
1714
+ */
1715
+ storage?: StorageAdapter;
1345
1716
  /**
1346
1717
  * Account linking configuration for multi-SSO user linking.
1718
+ * Pass `true` or `"linkByEmail"` for automatic email-verified linking.
1347
1719
  */
1348
- accountLinking?: AccountLinkingConfig;
1720
+ accountLinking?: boolean | AccountLinkingMode | AccountLinkingConfig;
1349
1721
  /**
1350
1722
  * Optional custom state handler.
1351
1723
  * Handles state generation and storage during OAuth authorization flow.
@@ -1389,6 +1761,23 @@ export declare interface LixaConfig<TProviders extends Record<string, ProviderCo
1389
1761
  * If provided, all Lixa logs will be routed through this logger.
1390
1762
  */
1391
1763
  logger?: LixaLogger;
1764
+ /**
1765
+ * Session cookie name or dynamic resolution function.
1766
+ * Can accept a static string or `(lixa: Lixa, req?: unknown) => string`.
1767
+ * Automatically evaluated live against the instance when getSessionCookieName() is called.
1768
+ */
1769
+ sessionCookieName?: SessionCookieResolver;
1770
+ }
1771
+
1772
+ /**
1773
+ * Interface exposing identity information for dynamic session cookie name resolution.
1774
+ * @public
1775
+ */
1776
+ export declare interface LixaCookieContext {
1777
+ /**
1778
+ * Retrieves the currently active identity provider.
1779
+ */
1780
+ getIdentityProvider(): IIdentityProvider | undefined;
1392
1781
  }
1393
1782
 
1394
1783
  /**
@@ -1439,7 +1828,7 @@ export declare class LocalCredentialsStorage implements CredentialsStorage {
1439
1828
  * Log context for Lixa structured logging.
1440
1829
  * @public
1441
1830
  */
1442
- export declare type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource" | "Credentials";
1831
+ export declare type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource" | "Credentials" | "Identity";
1443
1832
 
1444
1833
  /**
1445
1834
  * Log level for Lixa structured logging.
@@ -1635,8 +2024,13 @@ export declare type ProviderConfig = {
1635
2024
  clientSecret: string;
1636
2025
  /** The redirect URI registered with the provider */
1637
2026
  redirectUri: string;
1638
- /** Array of OAuth scopes to request */
1639
- scopes: string[];
2027
+ /** Array of OAuth scopes to request. If omitted, uses provider default identity scopes. */
2028
+ scopes?: string[];
2029
+ /**
2030
+ * Default scopes requested when connecting this provider as a third-party resource (AuthZ).
2031
+ * Used automatically by getResourceAuthUrl() and handleResourceCallback() if not overridden at runtime.
2032
+ */
2033
+ resourceScopes?: string[];
1640
2034
  /**
1641
2035
  * Set to true to allow non-identity (resource) scopes during primary authentication flow.
1642
2036
  * By default (false), Lixa restricts primary AuthN scopes to identity scopes to maintain
@@ -1689,6 +2083,30 @@ export declare class RefreshTokenError extends LixaError {
1689
2083
  constructor(message: string, details?: Record<string, unknown>);
1690
2084
  }
1691
2085
 
2086
+ /**
2087
+ * Parameters for resending a sign up confirmation code.
2088
+ *
2089
+ * @public
2090
+ */
2091
+ export declare interface ResendConfirmationCodeParams {
2092
+ /** Username or email of the account */
2093
+ identifier: string;
2094
+ }
2095
+
2096
+ /**
2097
+ * Result of resending a sign up confirmation code.
2098
+ *
2099
+ * @public
2100
+ */
2101
+ export declare interface ResendConfirmationCodeResult {
2102
+ /** True if code was dispatched */
2103
+ success: boolean;
2104
+ /** Delivery medium (e.g. 'EMAIL' or 'SMS') */
2105
+ deliveryMedium?: string | undefined;
2106
+ /** Obscured destination */
2107
+ destination?: string | undefined;
2108
+ }
2109
+
1692
2110
  /**
1693
2111
  * Resource handler configuration.
1694
2112
  *
@@ -1806,6 +2224,55 @@ export declare class ScryptPasswordHasher implements IPasswordHasher {
1806
2224
  private deriveKey;
1807
2225
  }
1808
2226
 
2227
+ /**
2228
+ * Self-Managed Identity Provider implementation for Lixa.
2229
+ *
2230
+ * @remarks
2231
+ * Backed by custom database storage (Prisma, Drizzle, PostgreSQL, SQLite, MongoDB)
2232
+ * or local in-memory storage, with cryptographic password hashing (Scrypt, Argon2, PBKDF2)
2233
+ * and configurable password policy enforcement.
2234
+ *
2235
+ * @public
2236
+ */
2237
+ export declare class SelfManagedIdentityProvider implements IIdentityProvider {
2238
+ readonly name: string;
2239
+ private readonly manager;
2240
+ constructor(configOrManager?: CredentialsConfig | CredentialsManager);
2241
+ private mapUser;
2242
+ /**
2243
+ * Registers a new user.
2244
+ */
2245
+ signUp(params: SignUpParams): Promise<UserIdentity>;
2246
+ /**
2247
+ * Authenticates a user with password.
2248
+ */
2249
+ signIn(params: SignInParams): Promise<IdentityAuthResult>;
2250
+ /**
2251
+ * Verifies credentials without throwing an error if invalid.
2252
+ */
2253
+ verifyCredentials(params: VerifyCredentialsParams): Promise<UserIdentity | null>;
2254
+ /**
2255
+ * Changes a user's password.
2256
+ */
2257
+ changePassword(params: ChangePasswordParams): Promise<boolean>;
2258
+ /**
2259
+ * Retrieves a user by their unique ID.
2260
+ */
2261
+ getUserById(id: string): Promise<UserIdentity | null>;
2262
+ /**
2263
+ * Retrieves a user by their identifier (email or username).
2264
+ */
2265
+ getUserByIdentifier(identifier: string): Promise<UserIdentity | null>;
2266
+ /**
2267
+ * Deletes a user from storage if supported by the storage adapter.
2268
+ */
2269
+ deleteUser(id: string): Promise<void>;
2270
+ /**
2271
+ * Returns the underlying CredentialsManager instance.
2272
+ */
2273
+ getCredentialsManager(): CredentialsManager;
2274
+ }
2275
+
1809
2276
  /**
1810
2277
  * Serializes a cookie name, value, and options into a standard `Set-Cookie` header string.
1811
2278
  *
@@ -1832,9 +2299,9 @@ export declare function serializeCookie(name: string, value: string, options?: C
1832
2299
  */
1833
2300
  export declare interface Session<TRaw = OAuthTokenResponse> {
1834
2301
  /**
1835
- * Unique session ID generated by Lixa upon authentication.
2302
+ * Unique canonical session ID generated by Lixa upon authentication.
1836
2303
  */
1837
- id?: string | undefined;
2304
+ sessionId?: string | undefined;
1838
2305
  /**
1839
2306
  * Linked identity provider accounts (AuthN) keyed by provider name.
1840
2307
  * Single source of truth for all authenticated user SSO identities.
@@ -1861,6 +2328,14 @@ export declare interface Session<TRaw = OAuthTokenResponse> {
1861
2328
  raw?: TRaw | undefined;
1862
2329
  }
1863
2330
 
2331
+ /**
2332
+ * Dynamic resolver for session cookie name.
2333
+ * Can be a static string or a dynamic callback receiving the Lixa instance and an optional request context.
2334
+ *
2335
+ * @public
2336
+ */
2337
+ export declare type SessionCookieResolver<TContext extends LixaCookieContext = LixaCookieContext> = string | ((lixa: TContext, req?: unknown) => string);
2338
+
1864
2339
  /**
1865
2340
  * Session handler for OAuth authentication.
1866
2341
  *
@@ -2024,9 +2499,9 @@ export declare interface SignInParams {
2024
2499
  *
2025
2500
  * @public
2026
2501
  */
2027
- export declare interface SignInResult<TSession = Session> {
2028
- /** Authenticated user credentials (with passwordHash omitted for safety) */
2029
- user: Omit<UserCredentials, "passwordHash">;
2502
+ export declare interface SignInResult<TSession = Session, TUser = UserIdentity> {
2503
+ /** Authenticated user profile / credentials (with passwordHash omitted for safety) */
2504
+ user: TUser;
2030
2505
  /** Active session ID */
2031
2506
  sessionId: string;
2032
2507
  /** Active session object */
@@ -2056,9 +2531,9 @@ export declare interface SignUpParams {
2056
2531
  *
2057
2532
  * @public
2058
2533
  */
2059
- export declare interface SignUpResult<TSession = Session> {
2060
- /** Created user credentials (with passwordHash omitted for safety) */
2061
- user: Omit<UserCredentials, "passwordHash">;
2534
+ export declare interface SignUpResult<TSession = Session, TUser = UserIdentity> {
2535
+ /** Created user profile / credentials (with passwordHash omitted for safety) */
2536
+ user: TUser;
2062
2537
  /** Created session ID if autoCreateSessionOnSignUp is enabled */
2063
2538
  sessionId?: string | undefined;
2064
2539
  /** Created session object if autoCreateSessionOnSignUp is enabled */
@@ -2258,6 +2733,19 @@ export declare interface StateStorage {
2258
2733
  deleteState(state: string): Promise<void>;
2259
2734
  }
2260
2735
 
2736
+ /**
2737
+ * Unified storage adapter interface (e.g. Prisma or Drizzle adapter).
2738
+ * When provided to Lixa via config.storage, automatically configures session, state, and resource storage.
2739
+ * @public
2740
+ */
2741
+ declare interface StorageAdapter {
2742
+ sessionStorage?: any;
2743
+ resourceStorage?: any;
2744
+ stateStorage?: any;
2745
+ credentialsStorage?: any;
2746
+ accountStorage?: any;
2747
+ }
2748
+
2261
2749
  /**
2262
2750
  * Thrown when exchanging an authorization code for OAuth tokens fails at the provider endpoint.
2263
2751
  *
@@ -2301,6 +2789,33 @@ export declare interface UserCredentials {
2301
2789
  metadata?: Record<string, unknown> | undefined;
2302
2790
  }
2303
2791
 
2792
+ /**
2793
+ * Standardized user identity representation across all identity providers
2794
+ * (Self-Managed Database, AWS Cognito, Auth0, Okta, Firebase, etc.).
2795
+ *
2796
+ * @public
2797
+ */
2798
+ export declare interface UserIdentity {
2799
+ /** Unique user identifier (UUID, Sub, Auth0 user_id, Okta id) */
2800
+ id: string;
2801
+ /** Primary unique lookup identifier (email or username) */
2802
+ identifier: string;
2803
+ /** Associated email address if available */
2804
+ email?: string | undefined;
2805
+ /** Username of the account if available */
2806
+ username?: string | undefined;
2807
+ /** Whether the email address has been verified by the identity provider */
2808
+ emailVerified?: boolean | undefined;
2809
+ /** Unix timestamp in milliseconds when user was created */
2810
+ createdAt?: number | undefined;
2811
+ /** Unix timestamp in milliseconds when user was last updated */
2812
+ updatedAt?: number | undefined;
2813
+ /** Custom user metadata or profile attributes */
2814
+ metadata?: Record<string, unknown> | undefined;
2815
+ /** Identity provider name (e.g. "self-managed", "cognito", "auth0", "okta") */
2816
+ provider?: string | undefined;
2817
+ }
2818
+
2304
2819
  /**
2305
2820
  * User information extracted from OAuth provider
2306
2821
  *