@vunexa/lixa 0.0.1-alpha.9 → 0.1.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.
Files changed (52) hide show
  1. package/README.md +263 -143
  2. package/dist/dao/session-cache.d.ts +11 -0
  3. package/dist/dao/session-cache.d.ts.map +1 -0
  4. package/dist/dao/state-cache.d.ts +8 -6
  5. package/dist/dao/state-cache.d.ts.map +1 -1
  6. package/dist/dao/types.d.ts +376 -3
  7. package/dist/dao/types.d.ts.map +1 -1
  8. package/dist/export-types/index.d.ts +1397 -0
  9. package/dist/export-types/tsdoc-metadata.json +11 -0
  10. package/dist/index.cjs +1035 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.cts +1361 -0
  13. package/dist/index.d.ts +11 -2
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +992 -9
  16. package/dist/index.js.map +1 -1
  17. package/dist/lixa.d.ts +280 -15
  18. package/dist/lixa.d.ts.map +1 -1
  19. package/dist/models/session.d.ts +316 -0
  20. package/dist/models/session.d.ts.map +1 -0
  21. package/dist/providers/IProvider.d.ts +127 -4
  22. package/dist/providers/IProvider.d.ts.map +1 -1
  23. package/dist/providers/index.d.ts +0 -2
  24. package/dist/providers/index.d.ts.map +1 -1
  25. package/dist/types.d.ts +195 -24
  26. package/dist/types.d.ts.map +1 -1
  27. package/dist/utils/user-info.d.ts +82 -0
  28. package/dist/utils/user-info.d.ts.map +1 -0
  29. package/package.json +15 -10
  30. package/dist/dao/state-cache.js +0 -18
  31. package/dist/dao/state-cache.js.map +0 -1
  32. package/dist/dao/types.js +0 -2
  33. package/dist/dao/types.js.map +0 -1
  34. package/dist/lixa.js +0 -244
  35. package/dist/lixa.js.map +0 -1
  36. package/dist/providers/IProvider.js +0 -2
  37. package/dist/providers/IProvider.js.map +0 -1
  38. package/dist/providers/github.d.ts +0 -9
  39. package/dist/providers/github.d.ts.map +0 -1
  40. package/dist/providers/github.js +0 -8
  41. package/dist/providers/github.js.map +0 -1
  42. package/dist/providers/google.d.ts +0 -9
  43. package/dist/providers/google.d.ts.map +0 -1
  44. package/dist/providers/google.js +0 -8
  45. package/dist/providers/google.js.map +0 -1
  46. package/dist/providers/index.js +0 -3
  47. package/dist/providers/index.js.map +0 -1
  48. package/dist/types.js +0 -2
  49. package/dist/types.js.map +0 -1
  50. package/dist/utils/constants.js +0 -4
  51. package/dist/utils/constants.js.map +0 -1
  52. package/index.d.ts +0 -229
package/dist/lixa.js DELETED
@@ -1,244 +0,0 @@
1
- import { randomBytes } from "crypto";
2
- import { LocalStateCache } from "./dao/state-cache";
3
- import crypto from "crypto";
4
- /**
5
- * A flexible, provider-agnostic OAuth 2.0 and OpenID Connect (OIDC) client library.
6
- *
7
- * @remarks
8
- * Lixa simplifies multi-provider authentication flows and supports extensible session management.
9
- *
10
- * @example
11
- * ```typescript
12
- * const lixa = new Lixa({
13
- * providers: {
14
- * google: {
15
- * clientId: 'your-client-id',
16
- * clientSecret: 'your-client-secret',
17
- * redirectUri: 'https://yourapp.com/auth/google/callback',
18
- * scopes: ['openid', 'email', 'profile']
19
- * }
20
- * }
21
- * });
22
- * ```
23
- *
24
- * @public
25
- */
26
- class Lixa {
27
- static CONFIGURED_PROVIDERS = new Map();
28
- static LOCAL_STATE_CACHE = new LocalStateCache();
29
- config;
30
- stateDao;
31
- /**
32
- * Creates a new Lixa instance with the provided configuration.
33
- *
34
- * @param config - The configuration object containing provider settings and optional session strategy
35
- */
36
- constructor(config) {
37
- this.config = config;
38
- this.stateDao = config.stateDao || Lixa.LOCAL_STATE_CACHE;
39
- }
40
- /**
41
- * Checks if a provider is both registered and configured for this instance.
42
- * This is a type guard that narrows the provider type for use with getAuthUrl.
43
- *
44
- * @param provider - The provider name to check (case-insensitive)
45
- * @returns True if the provider is registered and configured, false otherwise
46
- *
47
- * @example
48
- * ```typescript
49
- * if (lixa.isProviderConfigured(provider)) {
50
- * // TypeScript now knows provider is a valid ConfiguredProviderKey
51
- * const authUrl = lixa.getAuthUrl(provider, state);
52
- * }
53
- * ```
54
- */
55
- isProviderConfigured(provider) {
56
- const providerType = provider.toLowerCase();
57
- return Lixa.CONFIGURED_PROVIDERS.has(providerType) &&
58
- this.config.providers.hasOwnProperty(providerType);
59
- }
60
- /**
61
- * Registers custom OAuth providers for use with Lixa.
62
- *
63
- * @param providerMap - A map of provider names to IProvider implementations
64
- *
65
- * @example
66
- * ```typescript
67
- * class CustomProvider implements IProvider {
68
- * authorizationEndpoint = 'https://custom.com/oauth/authorize';
69
- * tokenEndpoint = 'https://custom.com/oauth/token';
70
- * userInfoEndpoint = 'https://custom.com/api/user';
71
- * }
72
- *
73
- * Lixa.registerProvider({ custom: new CustomProvider() });
74
- * ```
75
- */
76
- static registerProvider(providerMap) {
77
- // This is a static method, so we can't access instance properties.
78
- // Instead, we can modify the prototype to add the new provider.
79
- Object.entries(providerMap).forEach(([key, providerImpl]) => {
80
- Lixa.CONFIGURED_PROVIDERS.set(key, providerImpl);
81
- });
82
- }
83
- /**
84
- * Generates a cryptographically secure random state parameter for OAuth flows.
85
- *
86
- * @returns A 32-character hexadecimal string
87
- *
88
- * @remarks
89
- * The state parameter is used to prevent CSRF attacks in OAuth flows.
90
- */
91
- static generateRandomState() {
92
- return randomBytes(16).toString("hex");
93
- }
94
- /**
95
- * Generates a cryptographically secure code verifier for PKCE flows.
96
- *
97
- * @returns A 64-character hexadecimal string
98
- *
99
- * @remarks
100
- * The code verifier is used in PKCE (Proof Key for Code Exchange) to enhance security.
101
- */
102
- static generateCodeVerifier() {
103
- return randomBytes(32).toString("hex");
104
- }
105
- static buildCodeChallenge(codeVerifier) {
106
- const hash = crypto
107
- .createHash("sha256")
108
- .update(codeVerifier)
109
- .digest("base64");
110
- // Convert to base64url
111
- return hash.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
112
- }
113
- /**
114
- * Generates the authorization URL for the specified provider.
115
- *
116
- * @param provider - The provider name (must be a configured provider key)
117
- * @param state - The state parameter for CSRF protection
118
- * @returns The complete authorization URL to redirect users to
119
- *
120
- * @throws Error when the provider is not configured
121
- *
122
- * @example
123
- * ```typescript
124
- * const state = Lixa.generateRandomState();
125
- * const authUrl = lixa.getAuthUrl('google', state);
126
- * res.redirect(authUrl);
127
- * ```
128
- */
129
- getAuthUrl(provider, state) {
130
- const providerType = String(provider).toLowerCase();
131
- const providerConfig = this.findProviderByType(providerType);
132
- const providerImpl = Lixa.CONFIGURED_PROVIDERS.get(providerType);
133
- if (!providerConfig || !providerImpl) {
134
- throw new Error(`Provider ${providerType} not configured`);
135
- }
136
- const codeVerifier = Lixa.generateCodeVerifier();
137
- const codeChallenge = Lixa.buildCodeChallenge(codeVerifier);
138
- // Cache the state paramaeter with TTL of 5 minutes (300 seconds)
139
- // We dont care about value. we are onl interested in key existence
140
- this.stateDao.saveState(state, {
141
- createdAt: Date.now(),
142
- provider: providerType,
143
- codeVerifier,
144
- }, 300 // 5 minutes in seconds
145
- );
146
- const params = new URLSearchParams({
147
- client_id: providerConfig.clientId,
148
- redirect_uri: providerConfig.redirectUri,
149
- scope: providerConfig.scopes.join(" "),
150
- state,
151
- response_type: "code",
152
- code_challenge: codeChallenge,
153
- code_challenge_method: "S256",
154
- ...providerConfig.extraConfig,
155
- });
156
- return `${providerImpl.authorizationEndpoint}?${params.toString()}`;
157
- }
158
- /**
159
- * Handles the OAuth callback and creates a user session.
160
- *
161
- * @param provider - The provider name (must be a configured provider key)
162
- * @param code - The authorization code from the provider
163
- * @param state - The state parameter for validation
164
- * @returns A Promise that resolves to a Session object
165
- *
166
- * @throws Error when code or state is missing/invalid, or provider is not configured
167
- *
168
- * @example
169
- * ```typescript
170
- * const session = await lixa.handleCallback({
171
- * provider: 'google',
172
- * code: req.query.code,
173
- * state: req.query.state
174
- * });
175
- * ```
176
- */
177
- async handleCallback({ provider, code, state, }) {
178
- if (!code || code.trim() === "") {
179
- throw new Error("Invalid or missing code in callback");
180
- }
181
- if (!state || state.trim() === "") {
182
- throw new Error("Invalid or missing state in callback");
183
- }
184
- //Validate state here
185
- const cachedState = await this.stateDao.getState(state);
186
- if (!cachedState) {
187
- throw new Error("Invalid or expired state");
188
- }
189
- // State is valid, remove it from cache to prevent reuse
190
- await this.stateDao.deleteState(state);
191
- //Get code verifier from cached state
192
- const codeVerifier = cachedState.codeVerifier;
193
- const providerType = String(provider).toLowerCase();
194
- const providerConfig = this.findProviderByType(providerType);
195
- const providerImpl = Lixa.CONFIGURED_PROVIDERS.get(providerType);
196
- if (!providerConfig || !providerImpl) {
197
- throw new Error(`Provider ${String(provider)} not configured`);
198
- }
199
- // Exchange code for tokens and fetch user info here.
200
- const tokens = await this.exchangeCodeForToken(code, providerConfig, providerImpl, codeVerifier);
201
- // For simplicity, we'll just return the tokens as the session.
202
- // In a real implementation, you'd fetch user info and create a session.
203
- const session = {
204
- token: tokens.access_token,
205
- raw: tokens, // Replace with actual user info
206
- };
207
- // If a session strategy is provided, use it to create a session.
208
- if (this.config.sessionStrategy) {
209
- return this.config.sessionStrategy.createSession(session.raw);
210
- }
211
- return session;
212
- }
213
- async exchangeCodeForToken(code, providerConfig, providerImpl, codeVerifier) {
214
- // Build the request body
215
- const body = {
216
- client_id: providerConfig.clientId,
217
- client_secret: providerConfig.clientSecret,
218
- code,
219
- redirect_uri: providerConfig.redirectUri,
220
- grant_type: "authorization_code",
221
- };
222
- if (codeVerifier) {
223
- body.code_verifier = codeVerifier;
224
- }
225
- const params = new URLSearchParams(body);
226
- const response = await fetch(providerImpl.tokenEndpoint, {
227
- method: "POST",
228
- headers: {
229
- "Content-Type": "application/x-www-form-urlencoded",
230
- Accept: "application/json",
231
- },
232
- body: params.toString(),
233
- });
234
- if (!response.ok) {
235
- throw new Error(`Token exchange failed: ${response.status} ${response.statusText}`);
236
- }
237
- return response.json();
238
- }
239
- findProviderByType(providerType) {
240
- return this.config.providers[providerType];
241
- }
242
- }
243
- export { Lixa };
244
- //# sourceMappingURL=lixa.js.map
package/dist/lixa.js.map DELETED
@@ -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;QAEzC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE;YACvD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,mCAAmC;gBACnD,MAAM,EAAE,kBAAkB;aAC3B;YACD,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE;SACxB,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,0BAA0B,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CACnE,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAEO,kBAAkB,CAAC,YAAoB;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC;;AAGH,OAAO,EAAE,IAAI,EAAE,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=IProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../src/providers/IProvider.ts"],"names":[],"mappings":""}
@@ -1,9 +0,0 @@
1
- import { IProvider } from "./IProvider";
2
- declare class GithubProvider implements IProvider {
3
- providerType: string;
4
- authorizationEndpoint: string;
5
- tokenEndpoint: string;
6
- userInfoEndpoint: string;
7
- }
8
- export { GithubProvider };
9
- //# sourceMappingURL=github.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../src/providers/github.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,cAAM,cAAe,YAAW,SAAS;IACvC,YAAY,SAAY;IACxB,qBAAqB,SAA8C;IACnE,aAAa,SAAiD;IAC9D,gBAAgB,SAAiC;CAClD;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,8 +0,0 @@
1
- class GithubProvider {
2
- providerType = "GITHUB";
3
- authorizationEndpoint = "https://github.com/login/oauth/authorize";
4
- tokenEndpoint = "https://github.com/login/oauth/access_token";
5
- userInfoEndpoint = "https://api.github.com/user";
6
- }
7
- export { GithubProvider };
8
- //# sourceMappingURL=github.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"github.js","sourceRoot":"","sources":["../../src/providers/github.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc;IAClB,YAAY,GAAG,QAAQ,CAAC;IACxB,qBAAqB,GAAG,0CAA0C,CAAC;IACnE,aAAa,GAAG,6CAA6C,CAAC;IAC9D,gBAAgB,GAAG,6BAA6B,CAAC;CAClD;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,9 +0,0 @@
1
- import { IProvider } from "./IProvider";
2
- declare class GoogleProvider implements IProvider {
3
- providerType: string;
4
- authorizationEndpoint: string;
5
- tokenEndpoint: string;
6
- userInfoEndpoint: string;
7
- }
8
- export { GoogleProvider };
9
- //# sourceMappingURL=google.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,cAAM,cAAe,YAAW,SAAS;IACvC,YAAY,SAAY;IACxB,qBAAqB,SAAkD;IACvE,aAAa,SAAyC;IACtD,gBAAgB,SAAmD;CACpE;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,8 +0,0 @@
1
- class GoogleProvider {
2
- providerType = "GOOGLE";
3
- authorizationEndpoint = "https://accounts.google.com/o/oauth2/v2/auth";
4
- tokenEndpoint = "https://oauth2.googleapis.com/token";
5
- userInfoEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo";
6
- }
7
- export { GoogleProvider };
8
- //# sourceMappingURL=google.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc;IAClB,YAAY,GAAG,QAAQ,CAAC;IACxB,qBAAqB,GAAG,8CAA8C,CAAC;IACvE,aAAa,GAAG,qCAAqC,CAAC;IACtD,gBAAgB,GAAG,+CAA+C,CAAC;CACpE;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,3 +0,0 @@
1
- export { GithubProvider } from "./github";
2
- export { GoogleProvider } from "./google";
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,4 +0,0 @@
1
- const GOOGLE = "google";
2
- const GITHUB = "github";
3
- export { GOOGLE, GITHUB };
4
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,QAAQ,CAAC;AACxB,MAAM,MAAM,GAAG,QAAQ,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC"}
package/index.d.ts DELETED
@@ -1,229 +0,0 @@
1
- /**
2
- * A flexible, provider-agnostic OAuth 2.0 and OpenID Connect (OIDC) client library for backend applications.
3
- *
4
- * @remarks
5
- * This package simplifies multi-provider authentication flows (e.g., Google, GitHub), supports extensible session management, and enables custom provider registration.
6
- *
7
- * @packageDocumentation
8
- */
9
-
10
- /**
11
- * Type representing the keys of configured providers
12
- */
13
- declare type ConfiguredProviderKey<T extends LixaConfig> = keyof T['providers'];
14
-
15
- /**
16
- * Interface for OAuth provider implementations.
17
- *
18
- * @remarks
19
- * Implement this interface to add support for custom OAuth providers.
20
- *
21
- * @public
22
- */
23
- export declare interface IProvider {
24
- /** The OAuth authorization endpoint URL */
25
- authorizationEndpoint: string;
26
- /** The OAuth token exchange endpoint URL */
27
- tokenEndpoint: string;
28
- /** The user information endpoint URL */
29
- userInfoEndpoint: string;
30
- }
31
-
32
- /**
33
- * A flexible, provider-agnostic OAuth 2.0 and OpenID Connect (OIDC) client library.
34
- *
35
- * @remarks
36
- * Lixa simplifies multi-provider authentication flows and supports extensible session management.
37
- *
38
- * @example
39
- * ```typescript
40
- * const lixa = new Lixa({
41
- * providers: {
42
- * google: {
43
- * clientId: 'your-client-id',
44
- * clientSecret: 'your-client-secret',
45
- * redirectUri: 'https://yourapp.com/auth/google/callback',
46
- * scopes: ['openid', 'email', 'profile']
47
- * }
48
- * }
49
- * });
50
- * ```
51
- *
52
- * @public
53
- */
54
- export declare class Lixa<TConfig extends LixaConfig = LixaConfig> {
55
- private static CONFIGURED_PROVIDERS;
56
- private static LOCAL_STATE_CACHE;
57
- private config;
58
- private stateDao;
59
- /**
60
- * Creates a new Lixa instance with the provided configuration.
61
- *
62
- * @param config - The configuration object containing provider settings and optional session strategy
63
- */
64
- constructor(config: TConfig);
65
- /**
66
- * Checks if a provider is both registered and configured for this instance.
67
- * This is a type guard that narrows the provider type for use with getAuthUrl.
68
- *
69
- * @param provider - The provider name to check (case-insensitive)
70
- * @returns True if the provider is registered and configured, false otherwise
71
- *
72
- * @example
73
- * ```typescript
74
- * if (lixa.isProviderConfigured(provider)) {
75
- * // TypeScript now knows provider is a valid ConfiguredProviderKey
76
- * const authUrl = lixa.getAuthUrl(provider, state);
77
- * }
78
- * ```
79
- */
80
- isProviderConfigured<T extends string>(provider: T): provider is T & ConfiguredProviderKey<TConfig>;
81
- /**
82
- * Registers custom OAuth providers for use with Lixa.
83
- *
84
- * @param providerMap - A map of provider names to IProvider implementations
85
- *
86
- * @example
87
- * ```typescript
88
- * class CustomProvider implements IProvider {
89
- * authorizationEndpoint = 'https://custom.com/oauth/authorize';
90
- * tokenEndpoint = 'https://custom.com/oauth/token';
91
- * userInfoEndpoint = 'https://custom.com/api/user';
92
- * }
93
- *
94
- * Lixa.registerProvider({ custom: new CustomProvider() });
95
- * ```
96
- */
97
- static registerProvider(providerMap: {
98
- [key: string]: IProvider;
99
- }): void;
100
- /**
101
- * Generates a cryptographically secure random state parameter for OAuth flows.
102
- *
103
- * @returns A 32-character hexadecimal string
104
- *
105
- * @remarks
106
- * The state parameter is used to prevent CSRF attacks in OAuth flows.
107
- */
108
- static generateRandomState(): string;
109
- /**
110
- * Generates a cryptographically secure code verifier for PKCE flows.
111
- *
112
- * @returns A 64-character hexadecimal string
113
- *
114
- * @remarks
115
- * The code verifier is used in PKCE (Proof Key for Code Exchange) to enhance security.
116
- */
117
- private static generateCodeVerifier;
118
- private static buildCodeChallenge;
119
- /**
120
- * Generates the authorization URL for the specified provider.
121
- *
122
- * @param provider - The provider name (must be a configured provider key)
123
- * @param state - The state parameter for CSRF protection
124
- * @returns The complete authorization URL to redirect users to
125
- *
126
- * @throws Error when the provider is not configured
127
- *
128
- * @example
129
- * ```typescript
130
- * const state = Lixa.generateRandomState();
131
- * const authUrl = lixa.getAuthUrl('google', state);
132
- * res.redirect(authUrl);
133
- * ```
134
- */
135
- getAuthUrl(provider: ConfiguredProviderKey<TConfig> | string, state: string): string;
136
- /**
137
- * Handles the OAuth callback and creates a user session.
138
- *
139
- * @param provider - The provider name (must be a configured provider key)
140
- * @param code - The authorization code from the provider
141
- * @param state - The state parameter for validation
142
- * @returns A Promise that resolves to a Session object
143
- *
144
- * @throws Error when code or state is missing/invalid, or provider is not configured
145
- *
146
- * @example
147
- * ```typescript
148
- * const session = await lixa.handleCallback({
149
- * provider: 'google',
150
- * code: req.query.code,
151
- * state: req.query.state
152
- * });
153
- * ```
154
- */
155
- handleCallback({ provider, code, state, }: {
156
- provider: ConfiguredProviderKey<TConfig> | string;
157
- code: string;
158
- state?: string;
159
- }): Promise<Session>;
160
- private exchangeCodeForToken;
161
- private findProviderByType;
162
- }
163
-
164
- /**
165
- * Main configuration object for Lixa.
166
- *
167
- * @public
168
- */
169
- export declare interface LixaConfig {
170
- /** Map of provider names to their configurations */
171
- providers: Record<string, ProviderConfig>;
172
- /** Optional custom session creation strategy */
173
- sessionStrategy?: SessionStrategy;
174
- /** Optional custom state storage implementation */
175
- stateDao?: StateDao;
176
- }
177
-
178
- /**
179
- * Configuration for an OAuth provider.
180
- *
181
- * @public
182
- */
183
- export declare interface ProviderConfig {
184
- /** The OAuth client ID provided by the provider */
185
- clientId: string;
186
- /** The OAuth client secret provided by the provider */
187
- clientSecret: string;
188
- /** The redirect URI registered with the provider */
189
- redirectUri: string;
190
- /** Array of OAuth scopes to request */
191
- scopes: string[];
192
- /** Additional provider-specific configuration parameters */
193
- extraConfig?: Record<string, any>;
194
- }
195
-
196
- /**
197
- * Represents a user session after successful OAuth authentication.
198
- *
199
- * @public
200
- */
201
- export declare interface Session {
202
- /** The session token (typically the access token) */
203
- token: string;
204
- /** Raw token data from the OAuth provider */
205
- raw: any;
206
- }
207
-
208
- /**
209
- * Strategy interface for custom session creation.
210
- *
211
- * @public
212
- */
213
- export declare interface SessionStrategy {
214
- /**
215
- * Creates a session from OAuth token data.
216
- *
217
- * @param userInfo - The token data received from the OAuth provider
218
- * @returns A Promise that resolves to a Session object
219
- */
220
- createSession(userInfo: any): Promise<Session>;
221
- }
222
-
223
- declare interface StateDao {
224
- saveState(state: string, data: any, expiresInSeconds: number): Promise<void>;
225
- getState(state: string): Promise<any | null>;
226
- deleteState(state: string): Promise<void>;
227
- }
228
-
229
- export { }