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