shogun-core 3.3.7 → 4.0.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 (55) hide show
  1. package/README.md +1378 -1221
  2. package/dist/browser/shogun-core.js +78074 -45286
  3. package/dist/browser/shogun-core.js.map +1 -1
  4. package/dist/core.js +2 -3
  5. package/dist/examples/simple-api-test.js +90 -65
  6. package/dist/examples/zkproof-credentials-example.js +218 -0
  7. package/dist/examples/zkproof-example.js +206 -0
  8. package/dist/gundb/api.js +111 -467
  9. package/dist/index.js +10 -1
  10. package/dist/interfaces/shogun.js +2 -2
  11. package/dist/managers/AuthManager.js +0 -2
  12. package/dist/managers/CoreInitializer.js +9 -12
  13. package/dist/plugins/index.js +9 -21
  14. package/dist/plugins/nostr/nostrConnectorPlugin.js +2 -2
  15. package/dist/plugins/webauthn/webauthn.js +20 -7
  16. package/dist/plugins/webauthn/webauthnPlugin.js +101 -17
  17. package/dist/plugins/zkproof/index.js +53 -0
  18. package/dist/plugins/zkproof/zkCredentials.js +213 -0
  19. package/dist/plugins/zkproof/zkProofConnector.js +198 -0
  20. package/dist/plugins/zkproof/zkProofPlugin.js +272 -0
  21. package/dist/types/core.d.ts +1 -1
  22. package/dist/types/examples/simple-api-test.d.ts +6 -1
  23. package/dist/types/examples/zkproof-credentials-example.d.ts +12 -0
  24. package/dist/types/examples/zkproof-example.d.ts +11 -0
  25. package/dist/types/gundb/api.d.ts +77 -165
  26. package/dist/types/gundb/types.d.ts +1 -1
  27. package/dist/types/index.d.ts +1 -0
  28. package/dist/types/interfaces/events.d.ts +3 -3
  29. package/dist/types/interfaces/shogun.d.ts +9 -24
  30. package/dist/types/plugins/index.d.ts +5 -3
  31. package/dist/types/plugins/webauthn/types.d.ts +22 -1
  32. package/dist/types/plugins/webauthn/webauthn.d.ts +1 -1
  33. package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +23 -2
  34. package/dist/types/plugins/zkproof/index.d.ts +48 -0
  35. package/dist/types/plugins/zkproof/types.d.ts +123 -0
  36. package/dist/types/plugins/zkproof/zkCredentials.d.ts +112 -0
  37. package/dist/types/plugins/zkproof/zkProofConnector.d.ts +46 -0
  38. package/dist/types/plugins/zkproof/zkProofPlugin.d.ts +76 -0
  39. package/dist/types/utils/seedPhrase.d.ts +50 -0
  40. package/dist/types/utils/validation.d.ts +2 -2
  41. package/dist/utils/seedPhrase.js +97 -0
  42. package/dist/utils/validation.js +3 -1
  43. package/package.json +14 -8
  44. package/dist/examples/api-test.js +0 -273
  45. package/dist/migration-test.js +0 -96
  46. package/dist/plugins/oauth/index.js +0 -8
  47. package/dist/plugins/oauth/oauthConnector.js +0 -759
  48. package/dist/plugins/oauth/oauthPlugin.js +0 -400
  49. package/dist/types/examples/api-test.d.ts +0 -12
  50. package/dist/types/migration-test.d.ts +0 -16
  51. package/dist/types/plugins/oauth/index.d.ts +0 -3
  52. package/dist/types/plugins/oauth/oauthConnector.d.ts +0 -110
  53. package/dist/types/plugins/oauth/oauthPlugin.d.ts +0 -91
  54. package/dist/types/plugins/oauth/types.d.ts +0 -114
  55. /package/dist/plugins/{oauth → zkproof}/types.js +0 -0
@@ -1,400 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OAuthPlugin = void 0;
4
- const base_1 = require("../base");
5
- const oauthConnector_1 = require("./oauthConnector");
6
- const errorHandler_1 = require("../../utils/errorHandler");
7
- const storage_1 = require("../../storage/storage");
8
- /**
9
- * OAuth Plugin for ShogunCore
10
- * Provides authentication with external OAuth providers
11
- */
12
- class OAuthPlugin extends base_1.BasePlugin {
13
- /**
14
- * Constructor for OAuthPlugin
15
- * @param config - Initial configuration for OAuth
16
- */
17
- constructor(config) {
18
- super();
19
- this.name = "oauth";
20
- this.version = "1.0.0";
21
- this.description = "Provides OAuth authentication with external providers for ShogunCore";
22
- this.oauthConnector = null;
23
- this.config = {};
24
- this.storage = null;
25
- if (config) {
26
- this.config = config;
27
- }
28
- }
29
- /**
30
- * @inheritdoc
31
- */
32
- initialize(core) {
33
- this.core = core;
34
- this.storage = new storage_1.ShogunStorage();
35
- // Inizializziamo il connector OAuth con la configurazione già presente
36
- this.oauthConnector = new oauthConnector_1.OAuthConnector(this.config);
37
- // Valida la configurazione di sicurezza dopo l'inizializzazione
38
- this.validateOAuthSecurity();
39
- }
40
- /**
41
- * Valida la configurazione di sicurezza OAuth
42
- */
43
- validateOAuthSecurity() {
44
- if (!this.oauthConnector)
45
- return;
46
- const providers = this.oauthConnector.getAvailableProviders();
47
- for (const provider of providers) {
48
- const providerConfig = this.config.providers?.[provider];
49
- if (!providerConfig)
50
- continue;
51
- // Verifica che PKCE sia abilitato per tutti i provider
52
- if (!providerConfig.usePKCE && typeof window !== "undefined") {
53
- console.warn(`[oauthPlugin] Provider ${provider} non ha PKCE abilitato - non sicuro per browser`);
54
- }
55
- // Verifica che non ci sia client_secret nel browser (eccetto Google con PKCE)
56
- if (providerConfig.clientSecret && typeof window !== "undefined") {
57
- if (provider === "google" && providerConfig.usePKCE) {
58
- // Non lanciare errore per Google con PKCE
59
- continue;
60
- }
61
- else {
62
- console.error(`[oauthPlugin] Provider ${provider} ha client_secret configurato nel browser - RIMUOVERE`);
63
- throw new Error(`Client secret non può essere usato nel browser per ${provider}`);
64
- }
65
- }
66
- }
67
- }
68
- /**
69
- * Configure the OAuth plugin with provider settings
70
- * @param config - Configuration options for OAuth
71
- */
72
- configure(config) {
73
- // Deep merge provider maps to preserve both existing and new providers
74
- const mergedProviders = {
75
- ...(this.config.providers || {}),
76
- ...(config?.providers || {}),
77
- };
78
- this.config = { ...this.config, ...config, providers: mergedProviders };
79
- // Inizializza il connector se non è già stato fatto
80
- if (!this.oauthConnector) {
81
- this.oauthConnector = new oauthConnector_1.OAuthConnector(this.config);
82
- }
83
- else {
84
- // Update connector configuration se già inizializzato
85
- const conn = this.oauthConnector;
86
- if (typeof conn.updateConfig === "function") {
87
- conn.updateConfig(this.config);
88
- }
89
- else {
90
- // Fallback: recreate connector
91
- this.oauthConnector = new oauthConnector_1.OAuthConnector(this.config);
92
- }
93
- }
94
- // Validate security settings
95
- this.validateOAuthSecurity();
96
- }
97
- /**
98
- * @inheritdoc
99
- */
100
- destroy() {
101
- if (this.oauthConnector) {
102
- const conn = this.oauthConnector;
103
- if (typeof conn.cleanup === "function") {
104
- conn.cleanup();
105
- }
106
- }
107
- this.oauthConnector = null;
108
- this.storage = null;
109
- super.destroy();
110
- }
111
- /**
112
- * Ensure that the OAuth connector is initialized
113
- * @private
114
- */
115
- assertOAuthConnector() {
116
- this.assertInitialized();
117
- if (!this.oauthConnector) {
118
- throw new Error("OAuth connector not initialized");
119
- }
120
- return this.oauthConnector;
121
- }
122
- /**
123
- * @inheritdoc
124
- */
125
- isSupported() {
126
- try {
127
- const conn = this.assertOAuthConnector();
128
- return typeof conn.isSupported === "function" ? conn.isSupported() : true;
129
- }
130
- catch {
131
- // If connector is not available, return false
132
- return false;
133
- }
134
- }
135
- /**
136
- * @inheritdoc
137
- */
138
- getAvailableProviders() {
139
- try {
140
- const conn = this.assertOAuthConnector();
141
- return typeof conn.getAvailableProviders === "function"
142
- ? conn.getAvailableProviders()
143
- : [];
144
- }
145
- catch {
146
- // If connector is not available, return empty array
147
- return [];
148
- }
149
- }
150
- /**
151
- * @inheritdoc
152
- */
153
- async initiateOAuth(provider) {
154
- const conn = this.assertOAuthConnector();
155
- return conn.initiateOAuth(provider);
156
- }
157
- /**
158
- * @inheritdoc
159
- */
160
- async completeOAuth(provider, authCode, state) {
161
- const conn = this.assertOAuthConnector();
162
- return conn.completeOAuth(provider, authCode, state);
163
- }
164
- /**
165
- * @inheritdoc
166
- */
167
- async generateCredentials(userInfo, provider) {
168
- const conn = this.assertOAuthConnector();
169
- return conn.generateCredentials(userInfo, provider);
170
- }
171
- /**
172
- * Login with OAuth
173
- * @param provider - OAuth provider to use
174
- * @returns {Promise<AuthResult>} Authentication result
175
- * @description Authenticates user using OAuth with external providers
176
- * NOTE: This method only initiates the OAuth flow. The actual authentication
177
- * happens in handleOAuthCallback when the provider redirects back.
178
- */
179
- async login(provider) {
180
- try {
181
- const core = this.assertInitialized();
182
- if (!provider) {
183
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "PROVIDER_REQUIRED", "OAuth provider required for OAuth login");
184
- }
185
- if (!this.isSupported()) {
186
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENVIRONMENT, "OAUTH_UNAVAILABLE", "OAuth is not supported in this environment");
187
- }
188
- // Check if provider is available
189
- const availableProviders = this.getAvailableProviders();
190
- if (!availableProviders.includes(provider)) {
191
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "PROVIDER_NOT_CONFIGURED", `Provider ${provider} is not configured or available`);
192
- }
193
- // Initiate OAuth flow with the provider
194
- const oauthResult = await this.initiateOAuth(provider);
195
- if (!oauthResult.success) {
196
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.AUTHENTICATION, "OAUTH_INITIATION_FAILED", oauthResult.error || "Failed to initiate OAuth flow");
197
- }
198
- // In a browser environment, this would redirect to the OAuth provider
199
- // The frontend should handle the redirect and then call handleOAuthCallback
200
- // with the received code and state when the provider redirects back
201
- // Return early with the auth URL that the frontend should use for redirection
202
- return {
203
- success: true,
204
- redirectUrl: oauthResult.authUrl,
205
- pendingAuth: true,
206
- message: "Redirect to OAuth provider required to complete authentication",
207
- provider,
208
- authMethod: "oauth",
209
- };
210
- }
211
- catch (error) {
212
- // Handle both ShogunError and generic errors
213
- const errorType = error?.type || errorHandler_1.ErrorType.AUTHENTICATION;
214
- const errorCode = error?.code || "OAUTH_LOGIN_ERROR";
215
- const errorMessage = error?.message || "Unknown error during OAuth login";
216
- errorHandler_1.ErrorHandler.handle(errorType, errorCode, errorMessage, error);
217
- return { success: false, error: errorMessage };
218
- }
219
- }
220
- /**
221
- * Register new user with OAuth provider
222
- * @param provider - OAuth provider
223
- * @returns {Promise<SignUpResult>} Registration result
224
- */
225
- async signUp(provider) {
226
- try {
227
- const core = this.assertInitialized();
228
- if (!provider) {
229
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "PROVIDER_REQUIRED", "OAuth provider required for OAuth signup");
230
- }
231
- if (!this.isSupported()) {
232
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENVIRONMENT, "OAUTH_UNAVAILABLE", "OAuth is not supported in this environment");
233
- }
234
- // Check if provider is available
235
- const availableProviders = this.getAvailableProviders();
236
- if (!availableProviders.includes(provider)) {
237
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "PROVIDER_NOT_CONFIGURED", `Provider ${provider} is not configured or available`);
238
- }
239
- // Initiate OAuth flow with the provider
240
- const oauthResult = await this.initiateOAuth(provider);
241
- if (!oauthResult.success) {
242
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.AUTHENTICATION, "OAUTH_INITIATION_FAILED", oauthResult.error || "Failed to initiate OAuth flow");
243
- }
244
- // In a browser environment, this would redirect to the OAuth provider
245
- // The frontend should handle the redirect and then call handleOAuthCallback
246
- // with the received code and state when the provider redirects back
247
- // Return early with the auth URL that the frontend should use for redirection
248
- return {
249
- success: true,
250
- redirectUrl: oauthResult.authUrl,
251
- pendingAuth: true,
252
- message: "Redirect to OAuth provider required to complete registration",
253
- provider,
254
- authMethod: "oauth",
255
- };
256
- }
257
- catch (error) {
258
- // Handle both ShogunError and generic errors
259
- const errorType = error?.type || errorHandler_1.ErrorType.AUTHENTICATION;
260
- const errorCode = error?.code || "OAUTH_SIGNUP_ERROR";
261
- const errorMessage = error?.message || "Unknown error during OAuth signup";
262
- errorHandler_1.ErrorHandler.handle(errorType, errorCode, errorMessage, error);
263
- return { success: false, error: errorMessage };
264
- }
265
- }
266
- /**
267
- * Handle OAuth callback (for frontend integration)
268
- * This method would be called when the OAuth provider redirects back
269
- */
270
- async handleOAuthCallback(provider, authCode, state) {
271
- try {
272
- const core = this.assertInitialized();
273
- // Validazione di sicurezza pre-callback
274
- if (!authCode || !state) {
275
- throw new Error("Authorization code and state parameter are required");
276
- }
277
- // Complete the OAuth flow
278
- const result = await this.completeOAuth(provider, authCode, state);
279
- if (!result.success || !result.userInfo) {
280
- throw new Error(result.error || "Failed to complete OAuth flow");
281
- }
282
- // Genera credenziali da user info
283
- const credentials = await this.generateCredentials(result.userInfo, provider);
284
- // Set authentication method
285
- core.setAuthMethod("oauth");
286
- // Login o signup usando la chiave derivata
287
- const authResult = await this._loginOrSignUp(credentials.username, credentials.key);
288
- if (authResult.success) {
289
- // Store user info in user metadata
290
- if (core.user) {
291
- await core.user.put({
292
- oauth: {
293
- provider,
294
- id: result.userInfo.id,
295
- email: result.userInfo.email,
296
- name: result.userInfo.name,
297
- picture: result.userInfo.picture,
298
- lastLogin: Date.now(),
299
- },
300
- });
301
- }
302
- // Emit appropriate event
303
- const eventType = authResult.isNewUser ? "auth:signup" : "auth:login";
304
- core.emit(eventType, {
305
- userPub: authResult.userPub || "",
306
- username: credentials.username,
307
- method: "oauth",
308
- provider,
309
- });
310
- // Pulisci i dati OAuth scaduti dopo un login riuscito
311
- this.cleanupExpiredOAuthData();
312
- // Return auth result with OAuth user data included
313
- return {
314
- ...authResult,
315
- sea: authResult.sea, // Include SEA pair from core
316
- user: {
317
- userPub: authResult.userPub,
318
- username: credentials.username,
319
- email: result.userInfo.email,
320
- name: result.userInfo.name ||
321
- result.userInfo.email ||
322
- `OAuth User (${provider})`,
323
- picture: result.userInfo.picture,
324
- oauth: {
325
- provider,
326
- id: result.userInfo.id,
327
- email: result.userInfo.email,
328
- name: result.userInfo.name,
329
- picture: result.userInfo.picture,
330
- lastLogin: Date.now(),
331
- },
332
- },
333
- };
334
- }
335
- return authResult;
336
- }
337
- catch (error) {
338
- // Pulisci i dati OAuth anche in caso di errore
339
- this.cleanupExpiredOAuthData();
340
- return {
341
- success: false,
342
- error: error.message || "Failed to handle OAuth callback",
343
- };
344
- }
345
- }
346
- /**
347
- * Pulisce i dati OAuth scaduti
348
- */
349
- cleanupExpiredOAuthData() {
350
- if (this.oauthConnector) {
351
- // Il metodo cleanupExpiredOAuthData è privato nel connector
352
- // quindi usiamo il metodo pubblico clearUserCache
353
- const conn = this.oauthConnector;
354
- if (typeof conn.clearUserCache === "function") {
355
- conn.clearUserCache();
356
- }
357
- }
358
- }
359
- /**
360
- * Private helper to login or sign up a user
361
- */
362
- async _loginOrSignUp(username, k) {
363
- if (!this.core) {
364
- return { success: false, error: "Shogun core not available" };
365
- }
366
- // Try login first
367
- const loginResult = await this.core.login(username, "", k);
368
- if (loginResult.success) {
369
- // Session is automatically saved by the login method
370
- loginResult.isNewUser = false;
371
- // Include SEA pair from core
372
- if (this.core.user && this.core.user._?.sea) {
373
- loginResult.sea = this.core.user._.sea;
374
- }
375
- return loginResult;
376
- }
377
- // If login fails, try signup
378
- const signupResult = await this.core.signUp(username, undefined, k);
379
- if (signupResult.success) {
380
- // Immediately login after signup
381
- const postSignupLogin = await this.core.login(username, "", k);
382
- if (postSignupLogin.success) {
383
- // Session is automatically saved by the login method
384
- postSignupLogin.isNewUser = true;
385
- // Include SEA pair from core
386
- if (this.core.user && this.core.user._?.sea) {
387
- postSignupLogin.sea = this.core.user._.sea;
388
- }
389
- return postSignupLogin;
390
- }
391
- return {
392
- success: false,
393
- error: postSignupLogin.error || "Login failed after successful signup.",
394
- };
395
- }
396
- // Return the original signup error for other failures
397
- return signupResult;
398
- }
399
- }
400
- exports.OAuthPlugin = OAuthPlugin;
@@ -1,12 +0,0 @@
1
- /**
2
- * Esempio completo che mostra le differenze tra i vari metodi dell'API ShogunCore
3
- *
4
- * Questo esempio dimostra:
5
- * - get() vs getData() vs getNode() vs node() vs chain()
6
- * - put() vs set() vs putUserData() vs setUserData()
7
- * - remove() vs removeUserData()
8
- * - Operazioni globali vs operazioni utente
9
- */
10
- declare function demonstrateAPIDifferences(): Promise<void>;
11
- declare function showAPIDifferences(): void;
12
- export { demonstrateAPIDifferences, showAPIDifferences };
@@ -1,16 +0,0 @@
1
- /**
2
- * Migration test file to verify that the refactored ShogunCore
3
- * maintains the same public API as the original implementation
4
- */
5
- /**
6
- * Test function to verify API compatibility
7
- */
8
- export declare function testApiCompatibility(): void;
9
- /**
10
- * Test that the refactored implementation maintains the same static properties
11
- */
12
- export declare function testStaticProperties(): void;
13
- /**
14
- * Run all compatibility tests
15
- */
16
- export declare function runCompatibilityTests(): void;
@@ -1,3 +0,0 @@
1
- export { OAuthConnector } from "./oauthConnector";
2
- export { OAuthPlugin } from "./oauthPlugin";
3
- export type { OAuthPluginInterface, OAuthConfig, OAuthProvider, OAuthCredentials, OAuthConnectionResult, OAuthUserInfo, } from "./types";
@@ -1,110 +0,0 @@
1
- /**
2
- * OAuth Connector - Secure version for GunDB user creation
3
- */
4
- import { EventEmitter } from "../../utils/eventEmitter";
5
- import { OAuthConfig, OAuthProvider, OAuthUserInfo, OAuthCredentials, OAuthConnectionResult } from "./types";
6
- /**
7
- * OAuth Connector
8
- */
9
- export declare class OAuthConnector extends EventEmitter {
10
- private readonly DEFAULT_CONFIG;
11
- private config;
12
- private readonly userCache;
13
- private readonly memoryStorage;
14
- constructor(config?: Partial<OAuthConfig>);
15
- /**
16
- * Validates security configuration
17
- */
18
- private validateSecurityConfig;
19
- /**
20
- * Update the connector configuration
21
- * @param config - New configuration options
22
- */
23
- updateConfig(config: Partial<OAuthConfig>): void;
24
- /**
25
- * Get origin URL (browser or Node.js compatible)
26
- */
27
- private getOrigin;
28
- /**
29
- * Storage abstraction (browser sessionStorage or Node.js Map)
30
- */
31
- private setItem;
32
- private getItem;
33
- private removeItem;
34
- /**
35
- * Check if OAuth is supported
36
- */
37
- isSupported(): boolean;
38
- /**
39
- * Get available OAuth providers
40
- */
41
- getAvailableProviders(): OAuthProvider[];
42
- /**
43
- * Generate PKCE challenge for secure OAuth flow
44
- */
45
- private generatePKCEChallenge;
46
- /**
47
- * Calculate the PKCE code challenge from a code verifier.
48
- * Hashes the verifier using SHA-256 and then base64url encodes it.
49
- * @param verifier The code verifier string.
50
- * @returns The base64url-encoded SHA-256 hash of the verifier.
51
- */
52
- private calculatePKCECodeChallenge;
53
- /**
54
- * Encodes a buffer into a Base64URL-encoded string.
55
- * @param buffer The buffer to encode.
56
- * @returns The Base64URL-encoded string.
57
- */
58
- private base64urlEncode;
59
- /**
60
- * Generate cryptographically secure random string
61
- */
62
- private generateRandomString;
63
- /**
64
- * Initiate OAuth flow
65
- */
66
- initiateOAuth(provider: OAuthProvider): Promise<OAuthConnectionResult>;
67
- /**
68
- * Complete OAuth flow
69
- */
70
- completeOAuth(provider: OAuthProvider, authCode: string, state?: string): Promise<OAuthConnectionResult>;
71
- /**
72
- * Generate credentials from OAuth user info
73
- * Ora restituisce anche la chiave GunDB derivata (key)
74
- */
75
- generateCredentials(userInfo: OAuthUserInfo, provider: OAuthProvider): Promise<OAuthCredentials & {
76
- key: any;
77
- }>;
78
- /**
79
- * Exchange authorization code for access token
80
- */
81
- private exchangeCodeForToken;
82
- /**
83
- * Fetch user info from provider
84
- */
85
- private fetchUserInfo;
86
- /**
87
- * Normalize user info from different providers
88
- */
89
- private normalizeUserInfo;
90
- /**
91
- * Cache user info
92
- */
93
- private cacheUserInfo;
94
- /**
95
- * Get cached user info
96
- */
97
- getCachedUserInfo(userId: string, provider: OAuthProvider): OAuthUserInfo | null;
98
- /**
99
- * Clear user cache
100
- */
101
- clearUserCache(userId?: string, provider?: OAuthProvider): void;
102
- /**
103
- * Cleanup
104
- */
105
- cleanup(): void;
106
- /**
107
- * Clean up expired OAuth data from storage
108
- */
109
- private cleanupExpiredOAuthData;
110
- }
@@ -1,91 +0,0 @@
1
- import { BasePlugin } from "../base";
2
- import { ShogunCore } from "../../core";
3
- import { OAuthPluginInterface, OAuthConfig, OAuthProvider, OAuthConnectionResult, OAuthCredentials, OAuthUserInfo } from "./types";
4
- import { AuthResult, SignUpResult } from "../../interfaces/shogun";
5
- /**
6
- * OAuth Plugin for ShogunCore
7
- * Provides authentication with external OAuth providers
8
- */
9
- export declare class OAuthPlugin extends BasePlugin implements OAuthPluginInterface {
10
- name: string;
11
- version: string;
12
- description: string;
13
- private oauthConnector;
14
- private config;
15
- private storage;
16
- /**
17
- * Constructor for OAuthPlugin
18
- * @param config - Initial configuration for OAuth
19
- */
20
- constructor(config?: Partial<OAuthConfig>);
21
- /**
22
- * @inheritdoc
23
- */
24
- initialize(core: ShogunCore): void;
25
- /**
26
- * Valida la configurazione di sicurezza OAuth
27
- */
28
- private validateOAuthSecurity;
29
- /**
30
- * Configure the OAuth plugin with provider settings
31
- * @param config - Configuration options for OAuth
32
- */
33
- configure(config: Partial<OAuthConfig>): void;
34
- /**
35
- * @inheritdoc
36
- */
37
- destroy(): void;
38
- /**
39
- * Ensure that the OAuth connector is initialized
40
- * @private
41
- */
42
- private assertOAuthConnector;
43
- /**
44
- * @inheritdoc
45
- */
46
- isSupported(): boolean;
47
- /**
48
- * @inheritdoc
49
- */
50
- getAvailableProviders(): OAuthProvider[];
51
- /**
52
- * @inheritdoc
53
- */
54
- initiateOAuth(provider: OAuthProvider): Promise<OAuthConnectionResult>;
55
- /**
56
- * @inheritdoc
57
- */
58
- completeOAuth(provider: OAuthProvider, authCode: string, state?: string): Promise<OAuthConnectionResult>;
59
- /**
60
- * @inheritdoc
61
- */
62
- generateCredentials(userInfo: OAuthUserInfo, provider: OAuthProvider): Promise<OAuthCredentials>;
63
- /**
64
- * Login with OAuth
65
- * @param provider - OAuth provider to use
66
- * @returns {Promise<AuthResult>} Authentication result
67
- * @description Authenticates user using OAuth with external providers
68
- * NOTE: This method only initiates the OAuth flow. The actual authentication
69
- * happens in handleOAuthCallback when the provider redirects back.
70
- */
71
- login(provider: OAuthProvider): Promise<AuthResult>;
72
- /**
73
- * Register new user with OAuth provider
74
- * @param provider - OAuth provider
75
- * @returns {Promise<SignUpResult>} Registration result
76
- */
77
- signUp(provider: OAuthProvider): Promise<SignUpResult>;
78
- /**
79
- * Handle OAuth callback (for frontend integration)
80
- * This method would be called when the OAuth provider redirects back
81
- */
82
- handleOAuthCallback(provider: OAuthProvider, authCode: string, state: string): Promise<AuthResult>;
83
- /**
84
- * Pulisce i dati OAuth scaduti
85
- */
86
- private cleanupExpiredOAuthData;
87
- /**
88
- * Private helper to login or sign up a user
89
- */
90
- private _loginOrSignUp;
91
- }