shogun-core 3.0.3 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/dist/browser/shogun-core.js +0 -92128
- package/dist/browser/shogun-core.js.map +0 -1
- package/dist/config/simplified-config.js +0 -230
- package/dist/core.js +0 -338
- package/dist/gundb/crypto.js +0 -268
- package/dist/gundb/db.js +0 -1833
- package/dist/gundb/derive.js +0 -229
- package/dist/gundb/errors.js +0 -66
- package/dist/gundb/index.js +0 -6
- package/dist/gundb/restricted-put.js +0 -81
- package/dist/gundb/rxjs.js +0 -445
- package/dist/gundb/simple-api.js +0 -438
- package/dist/gundb/types.js +0 -4
- package/dist/index.js +0 -16
- package/dist/interfaces/common.js +0 -1
- package/dist/interfaces/events.js +0 -36
- package/dist/interfaces/plugin.js +0 -1
- package/dist/interfaces/shogun.js +0 -34
- package/dist/managers/AuthManager.js +0 -225
- package/dist/managers/CoreInitializer.js +0 -234
- package/dist/managers/EventManager.js +0 -67
- package/dist/managers/PluginManager.js +0 -296
- package/dist/migration-test.js +0 -91
- package/dist/plugins/base.js +0 -47
- package/dist/plugins/index.js +0 -15
- package/dist/plugins/nostr/index.js +0 -4
- package/dist/plugins/nostr/nostrConnector.js +0 -413
- package/dist/plugins/nostr/nostrConnectorPlugin.js +0 -446
- package/dist/plugins/nostr/nostrSigner.js +0 -313
- package/dist/plugins/nostr/types.js +0 -1
- package/dist/plugins/oauth/index.js +0 -3
- package/dist/plugins/oauth/oauthConnector.js +0 -753
- package/dist/plugins/oauth/oauthPlugin.js +0 -396
- package/dist/plugins/oauth/types.js +0 -1
- package/dist/plugins/web3/index.js +0 -4
- package/dist/plugins/web3/types.js +0 -1
- package/dist/plugins/web3/web3Connector.js +0 -528
- package/dist/plugins/web3/web3ConnectorPlugin.js +0 -448
- package/dist/plugins/web3/web3Signer.js +0 -308
- package/dist/plugins/webauthn/index.js +0 -3
- package/dist/plugins/webauthn/types.js +0 -11
- package/dist/plugins/webauthn/webauthn.js +0 -478
- package/dist/plugins/webauthn/webauthnPlugin.js +0 -398
- package/dist/plugins/webauthn/webauthnSigner.js +0 -304
- package/dist/storage/storage.js +0 -147
- package/dist/types/config/simplified-config.d.ts +0 -114
- package/dist/types/core.d.ts +0 -305
- package/dist/types/gundb/crypto.d.ts +0 -95
- package/dist/types/gundb/db.d.ts +0 -404
- package/dist/types/gundb/derive.d.ts +0 -21
- package/dist/types/gundb/errors.d.ts +0 -42
- package/dist/types/gundb/index.d.ts +0 -3
- package/dist/types/gundb/restricted-put.d.ts +0 -15
- package/dist/types/gundb/rxjs.d.ts +0 -110
- package/dist/types/gundb/simple-api.d.ts +0 -90
- package/dist/types/gundb/types.d.ts +0 -264
- package/dist/types/index.d.ts +0 -14
- package/dist/types/interfaces/common.d.ts +0 -85
- package/dist/types/interfaces/events.d.ts +0 -131
- package/dist/types/interfaces/plugin.d.ts +0 -162
- package/dist/types/interfaces/shogun.d.ts +0 -215
- package/dist/types/managers/AuthManager.d.ts +0 -72
- package/dist/types/managers/CoreInitializer.d.ts +0 -40
- package/dist/types/managers/EventManager.d.ts +0 -49
- package/dist/types/managers/PluginManager.d.ts +0 -145
- package/dist/types/migration-test.d.ts +0 -16
- package/dist/types/plugins/base.d.ts +0 -35
- package/dist/types/plugins/index.d.ts +0 -14
- package/dist/types/plugins/nostr/index.d.ts +0 -4
- package/dist/types/plugins/nostr/nostrConnector.d.ts +0 -119
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +0 -163
- package/dist/types/plugins/nostr/nostrSigner.d.ts +0 -105
- package/dist/types/plugins/nostr/types.d.ts +0 -122
- package/dist/types/plugins/oauth/index.d.ts +0 -3
- package/dist/types/plugins/oauth/oauthConnector.d.ts +0 -110
- package/dist/types/plugins/oauth/oauthPlugin.d.ts +0 -91
- package/dist/types/plugins/oauth/types.d.ts +0 -114
- package/dist/types/plugins/web3/index.d.ts +0 -4
- package/dist/types/plugins/web3/types.d.ts +0 -107
- package/dist/types/plugins/web3/web3Connector.d.ts +0 -129
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +0 -160
- package/dist/types/plugins/web3/web3Signer.d.ts +0 -114
- package/dist/types/plugins/webauthn/index.d.ts +0 -3
- package/dist/types/plugins/webauthn/types.d.ts +0 -162
- package/dist/types/plugins/webauthn/webauthn.d.ts +0 -129
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +0 -158
- package/dist/types/plugins/webauthn/webauthnSigner.d.ts +0 -91
- package/dist/types/storage/storage.d.ts +0 -50
- package/dist/types/utils/errorHandler.d.ts +0 -119
- package/dist/types/utils/eventEmitter.d.ts +0 -39
- package/dist/types/utils/validation.d.ts +0 -27
- package/dist/utils/errorHandler.js +0 -241
- package/dist/utils/eventEmitter.js +0 -76
- package/dist/utils/validation.js +0 -72
|
@@ -1,396 +0,0 @@
|
|
|
1
|
-
import { BasePlugin } from "../base";
|
|
2
|
-
import { OAuthConnector } from "./oauthConnector";
|
|
3
|
-
import { ErrorHandler, ErrorType, createError } from "../../utils/errorHandler";
|
|
4
|
-
import { ShogunStorage } from "../../storage/storage";
|
|
5
|
-
/**
|
|
6
|
-
* OAuth Plugin for ShogunCore
|
|
7
|
-
* Provides authentication with external OAuth providers
|
|
8
|
-
*/
|
|
9
|
-
export class OAuthPlugin extends BasePlugin {
|
|
10
|
-
name = "oauth";
|
|
11
|
-
version = "1.0.0";
|
|
12
|
-
description = "Provides OAuth authentication with external providers for ShogunCore";
|
|
13
|
-
oauthConnector = null;
|
|
14
|
-
config = {};
|
|
15
|
-
storage = null;
|
|
16
|
-
/**
|
|
17
|
-
* Constructor for OAuthPlugin
|
|
18
|
-
* @param config - Initial configuration for OAuth
|
|
19
|
-
*/
|
|
20
|
-
constructor(config) {
|
|
21
|
-
super();
|
|
22
|
-
if (config) {
|
|
23
|
-
this.config = config;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @inheritdoc
|
|
28
|
-
*/
|
|
29
|
-
initialize(core) {
|
|
30
|
-
this.core = core;
|
|
31
|
-
this.storage = new ShogunStorage();
|
|
32
|
-
// Inizializziamo il connector OAuth con la configurazione già presente
|
|
33
|
-
this.oauthConnector = new OAuthConnector(this.config);
|
|
34
|
-
// Valida la configurazione di sicurezza dopo l'inizializzazione
|
|
35
|
-
this.validateOAuthSecurity();
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Valida la configurazione di sicurezza OAuth
|
|
39
|
-
*/
|
|
40
|
-
validateOAuthSecurity() {
|
|
41
|
-
if (!this.oauthConnector)
|
|
42
|
-
return;
|
|
43
|
-
const providers = this.oauthConnector.getAvailableProviders();
|
|
44
|
-
for (const provider of providers) {
|
|
45
|
-
const providerConfig = this.config.providers?.[provider];
|
|
46
|
-
if (!providerConfig)
|
|
47
|
-
continue;
|
|
48
|
-
// Verifica che PKCE sia abilitato per tutti i provider
|
|
49
|
-
if (!providerConfig.usePKCE && typeof window !== "undefined") {
|
|
50
|
-
console.warn(`[oauthPlugin] Provider ${provider} non ha PKCE abilitato - non sicuro per browser`);
|
|
51
|
-
}
|
|
52
|
-
// Verifica che non ci sia client_secret nel browser (eccetto Google con PKCE)
|
|
53
|
-
if (providerConfig.clientSecret && typeof window !== "undefined") {
|
|
54
|
-
if (provider === "google" && providerConfig.usePKCE) {
|
|
55
|
-
// Non lanciare errore per Google con PKCE
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
console.error(`[oauthPlugin] Provider ${provider} ha client_secret configurato nel browser - RIMUOVERE`);
|
|
60
|
-
throw new Error(`Client secret non può essere usato nel browser per ${provider}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Configure the OAuth plugin with provider settings
|
|
67
|
-
* @param config - Configuration options for OAuth
|
|
68
|
-
*/
|
|
69
|
-
configure(config) {
|
|
70
|
-
// Deep merge provider maps to preserve both existing and new providers
|
|
71
|
-
const mergedProviders = {
|
|
72
|
-
...(this.config.providers || {}),
|
|
73
|
-
...(config?.providers || {}),
|
|
74
|
-
};
|
|
75
|
-
this.config = { ...this.config, ...config, providers: mergedProviders };
|
|
76
|
-
// Inizializza il connector se non è già stato fatto
|
|
77
|
-
if (!this.oauthConnector) {
|
|
78
|
-
this.oauthConnector = new OAuthConnector(this.config);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
// Update connector configuration se già inizializzato
|
|
82
|
-
const conn = this.oauthConnector;
|
|
83
|
-
if (typeof conn.updateConfig === "function") {
|
|
84
|
-
conn.updateConfig(this.config);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
// Fallback: recreate connector
|
|
88
|
-
this.oauthConnector = new OAuthConnector(this.config);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// Validate security settings
|
|
92
|
-
this.validateOAuthSecurity();
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* @inheritdoc
|
|
96
|
-
*/
|
|
97
|
-
destroy() {
|
|
98
|
-
if (this.oauthConnector) {
|
|
99
|
-
const conn = this.oauthConnector;
|
|
100
|
-
if (typeof conn.cleanup === "function") {
|
|
101
|
-
conn.cleanup();
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
this.oauthConnector = null;
|
|
105
|
-
this.storage = null;
|
|
106
|
-
super.destroy();
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Ensure that the OAuth connector is initialized
|
|
110
|
-
* @private
|
|
111
|
-
*/
|
|
112
|
-
assertOAuthConnector() {
|
|
113
|
-
this.assertInitialized();
|
|
114
|
-
if (!this.oauthConnector) {
|
|
115
|
-
throw new Error("OAuth connector not initialized");
|
|
116
|
-
}
|
|
117
|
-
return this.oauthConnector;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* @inheritdoc
|
|
121
|
-
*/
|
|
122
|
-
isSupported() {
|
|
123
|
-
try {
|
|
124
|
-
const conn = this.assertOAuthConnector();
|
|
125
|
-
return typeof conn.isSupported === "function" ? conn.isSupported() : true;
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
// If connector is not available, return false
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* @inheritdoc
|
|
134
|
-
*/
|
|
135
|
-
getAvailableProviders() {
|
|
136
|
-
try {
|
|
137
|
-
const conn = this.assertOAuthConnector();
|
|
138
|
-
return typeof conn.getAvailableProviders === "function"
|
|
139
|
-
? conn.getAvailableProviders()
|
|
140
|
-
: [];
|
|
141
|
-
}
|
|
142
|
-
catch {
|
|
143
|
-
// If connector is not available, return empty array
|
|
144
|
-
return [];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* @inheritdoc
|
|
149
|
-
*/
|
|
150
|
-
async initiateOAuth(provider) {
|
|
151
|
-
const conn = this.assertOAuthConnector();
|
|
152
|
-
return conn.initiateOAuth(provider);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* @inheritdoc
|
|
156
|
-
*/
|
|
157
|
-
async completeOAuth(provider, authCode, state) {
|
|
158
|
-
const conn = this.assertOAuthConnector();
|
|
159
|
-
return conn.completeOAuth(provider, authCode, state);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* @inheritdoc
|
|
163
|
-
*/
|
|
164
|
-
async generateCredentials(userInfo, provider) {
|
|
165
|
-
const conn = this.assertOAuthConnector();
|
|
166
|
-
return conn.generateCredentials(userInfo, provider);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Login with OAuth
|
|
170
|
-
* @param provider - OAuth provider to use
|
|
171
|
-
* @returns {Promise<AuthResult>} Authentication result
|
|
172
|
-
* @description Authenticates user using OAuth with external providers
|
|
173
|
-
* NOTE: This method only initiates the OAuth flow. The actual authentication
|
|
174
|
-
* happens in handleOAuthCallback when the provider redirects back.
|
|
175
|
-
*/
|
|
176
|
-
async login(provider) {
|
|
177
|
-
try {
|
|
178
|
-
const core = this.assertInitialized();
|
|
179
|
-
if (!provider) {
|
|
180
|
-
throw createError(ErrorType.VALIDATION, "PROVIDER_REQUIRED", "OAuth provider required for OAuth login");
|
|
181
|
-
}
|
|
182
|
-
if (!this.isSupported()) {
|
|
183
|
-
throw createError(ErrorType.ENVIRONMENT, "OAUTH_UNAVAILABLE", "OAuth is not supported in this environment");
|
|
184
|
-
}
|
|
185
|
-
// Check if provider is available
|
|
186
|
-
const availableProviders = this.getAvailableProviders();
|
|
187
|
-
if (!availableProviders.includes(provider)) {
|
|
188
|
-
throw createError(ErrorType.VALIDATION, "PROVIDER_NOT_CONFIGURED", `Provider ${provider} is not configured or available`);
|
|
189
|
-
}
|
|
190
|
-
// Initiate OAuth flow with the provider
|
|
191
|
-
const oauthResult = await this.initiateOAuth(provider);
|
|
192
|
-
if (!oauthResult.success) {
|
|
193
|
-
throw createError(ErrorType.AUTHENTICATION, "OAUTH_INITIATION_FAILED", oauthResult.error || "Failed to initiate OAuth flow");
|
|
194
|
-
}
|
|
195
|
-
// In a browser environment, this would redirect to the OAuth provider
|
|
196
|
-
// The frontend should handle the redirect and then call handleOAuthCallback
|
|
197
|
-
// with the received code and state when the provider redirects back
|
|
198
|
-
// Return early with the auth URL that the frontend should use for redirection
|
|
199
|
-
return {
|
|
200
|
-
success: true,
|
|
201
|
-
redirectUrl: oauthResult.authUrl,
|
|
202
|
-
pendingAuth: true,
|
|
203
|
-
message: "Redirect to OAuth provider required to complete authentication",
|
|
204
|
-
provider,
|
|
205
|
-
authMethod: "oauth",
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
// Handle both ShogunError and generic errors
|
|
210
|
-
const errorType = error?.type || ErrorType.AUTHENTICATION;
|
|
211
|
-
const errorCode = error?.code || "OAUTH_LOGIN_ERROR";
|
|
212
|
-
const errorMessage = error?.message || "Unknown error during OAuth login";
|
|
213
|
-
ErrorHandler.handle(errorType, errorCode, errorMessage, error);
|
|
214
|
-
return { success: false, error: errorMessage };
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Register new user with OAuth provider
|
|
219
|
-
* @param provider - OAuth provider
|
|
220
|
-
* @returns {Promise<SignUpResult>} Registration result
|
|
221
|
-
*/
|
|
222
|
-
async signUp(provider) {
|
|
223
|
-
try {
|
|
224
|
-
const core = this.assertInitialized();
|
|
225
|
-
if (!provider) {
|
|
226
|
-
throw createError(ErrorType.VALIDATION, "PROVIDER_REQUIRED", "OAuth provider required for OAuth signup");
|
|
227
|
-
}
|
|
228
|
-
if (!this.isSupported()) {
|
|
229
|
-
throw createError(ErrorType.ENVIRONMENT, "OAUTH_UNAVAILABLE", "OAuth is not supported in this environment");
|
|
230
|
-
}
|
|
231
|
-
// Check if provider is available
|
|
232
|
-
const availableProviders = this.getAvailableProviders();
|
|
233
|
-
if (!availableProviders.includes(provider)) {
|
|
234
|
-
throw createError(ErrorType.VALIDATION, "PROVIDER_NOT_CONFIGURED", `Provider ${provider} is not configured or available`);
|
|
235
|
-
}
|
|
236
|
-
// Initiate OAuth flow with the provider
|
|
237
|
-
const oauthResult = await this.initiateOAuth(provider);
|
|
238
|
-
if (!oauthResult.success) {
|
|
239
|
-
throw createError(ErrorType.AUTHENTICATION, "OAUTH_INITIATION_FAILED", oauthResult.error || "Failed to initiate OAuth flow");
|
|
240
|
-
}
|
|
241
|
-
// In a browser environment, this would redirect to the OAuth provider
|
|
242
|
-
// The frontend should handle the redirect and then call handleOAuthCallback
|
|
243
|
-
// with the received code and state when the provider redirects back
|
|
244
|
-
// Return early with the auth URL that the frontend should use for redirection
|
|
245
|
-
return {
|
|
246
|
-
success: true,
|
|
247
|
-
redirectUrl: oauthResult.authUrl,
|
|
248
|
-
pendingAuth: true,
|
|
249
|
-
message: "Redirect to OAuth provider required to complete registration",
|
|
250
|
-
provider,
|
|
251
|
-
authMethod: "oauth",
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
catch (error) {
|
|
255
|
-
// Handle both ShogunError and generic errors
|
|
256
|
-
const errorType = error?.type || ErrorType.AUTHENTICATION;
|
|
257
|
-
const errorCode = error?.code || "OAUTH_SIGNUP_ERROR";
|
|
258
|
-
const errorMessage = error?.message || "Unknown error during OAuth signup";
|
|
259
|
-
ErrorHandler.handle(errorType, errorCode, errorMessage, error);
|
|
260
|
-
return { success: false, error: errorMessage };
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Handle OAuth callback (for frontend integration)
|
|
265
|
-
* This method would be called when the OAuth provider redirects back
|
|
266
|
-
*/
|
|
267
|
-
async handleOAuthCallback(provider, authCode, state) {
|
|
268
|
-
try {
|
|
269
|
-
const core = this.assertInitialized();
|
|
270
|
-
// Validazione di sicurezza pre-callback
|
|
271
|
-
if (!authCode || !state) {
|
|
272
|
-
throw new Error("Authorization code and state parameter are required");
|
|
273
|
-
}
|
|
274
|
-
// Complete the OAuth flow
|
|
275
|
-
const result = await this.completeOAuth(provider, authCode, state);
|
|
276
|
-
if (!result.success || !result.userInfo) {
|
|
277
|
-
throw new Error(result.error || "Failed to complete OAuth flow");
|
|
278
|
-
}
|
|
279
|
-
// Genera credenziali da user info
|
|
280
|
-
const credentials = await this.generateCredentials(result.userInfo, provider);
|
|
281
|
-
// Set authentication method
|
|
282
|
-
core.setAuthMethod("oauth");
|
|
283
|
-
// Login o signup usando la chiave derivata
|
|
284
|
-
const authResult = await this._loginOrSignUp(credentials.username, credentials.key);
|
|
285
|
-
if (authResult.success) {
|
|
286
|
-
// Store user info in user metadata
|
|
287
|
-
if (core.user) {
|
|
288
|
-
await core.user.put({
|
|
289
|
-
oauth: {
|
|
290
|
-
provider,
|
|
291
|
-
id: result.userInfo.id,
|
|
292
|
-
email: result.userInfo.email,
|
|
293
|
-
name: result.userInfo.name,
|
|
294
|
-
picture: result.userInfo.picture,
|
|
295
|
-
lastLogin: Date.now(),
|
|
296
|
-
},
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
// Emit appropriate event
|
|
300
|
-
const eventType = authResult.isNewUser ? "auth:signup" : "auth:login";
|
|
301
|
-
core.emit(eventType, {
|
|
302
|
-
userPub: authResult.userPub || "",
|
|
303
|
-
username: credentials.username,
|
|
304
|
-
method: "oauth",
|
|
305
|
-
provider,
|
|
306
|
-
});
|
|
307
|
-
// Pulisci i dati OAuth scaduti dopo un login riuscito
|
|
308
|
-
this.cleanupExpiredOAuthData();
|
|
309
|
-
// Return auth result with OAuth user data included
|
|
310
|
-
return {
|
|
311
|
-
...authResult,
|
|
312
|
-
sea: authResult.sea, // Include SEA pair from core
|
|
313
|
-
user: {
|
|
314
|
-
userPub: authResult.userPub,
|
|
315
|
-
username: credentials.username,
|
|
316
|
-
email: result.userInfo.email,
|
|
317
|
-
name: result.userInfo.name ||
|
|
318
|
-
result.userInfo.email ||
|
|
319
|
-
`OAuth User (${provider})`,
|
|
320
|
-
picture: result.userInfo.picture,
|
|
321
|
-
oauth: {
|
|
322
|
-
provider,
|
|
323
|
-
id: result.userInfo.id,
|
|
324
|
-
email: result.userInfo.email,
|
|
325
|
-
name: result.userInfo.name,
|
|
326
|
-
picture: result.userInfo.picture,
|
|
327
|
-
lastLogin: Date.now(),
|
|
328
|
-
},
|
|
329
|
-
},
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
return authResult;
|
|
333
|
-
}
|
|
334
|
-
catch (error) {
|
|
335
|
-
// Pulisci i dati OAuth anche in caso di errore
|
|
336
|
-
this.cleanupExpiredOAuthData();
|
|
337
|
-
return {
|
|
338
|
-
success: false,
|
|
339
|
-
error: error.message || "Failed to handle OAuth callback",
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Pulisce i dati OAuth scaduti
|
|
345
|
-
*/
|
|
346
|
-
cleanupExpiredOAuthData() {
|
|
347
|
-
if (this.oauthConnector) {
|
|
348
|
-
// Il metodo cleanupExpiredOAuthData è privato nel connector
|
|
349
|
-
// quindi usiamo il metodo pubblico clearUserCache
|
|
350
|
-
const conn = this.oauthConnector;
|
|
351
|
-
if (typeof conn.clearUserCache === "function") {
|
|
352
|
-
conn.clearUserCache();
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Private helper to login or sign up a user
|
|
358
|
-
*/
|
|
359
|
-
async _loginOrSignUp(username, k) {
|
|
360
|
-
if (!this.core) {
|
|
361
|
-
return { success: false, error: "Shogun core not available" };
|
|
362
|
-
}
|
|
363
|
-
// Try login first
|
|
364
|
-
const loginResult = await this.core.login(username, "", k);
|
|
365
|
-
if (loginResult.success) {
|
|
366
|
-
// Session is automatically saved by the login method
|
|
367
|
-
loginResult.isNewUser = false;
|
|
368
|
-
// Include SEA pair from core
|
|
369
|
-
if (this.core.user && this.core.user._?.sea) {
|
|
370
|
-
loginResult.sea = this.core.user._.sea;
|
|
371
|
-
}
|
|
372
|
-
return loginResult;
|
|
373
|
-
}
|
|
374
|
-
// If login fails, try signup
|
|
375
|
-
const signupResult = await this.core.signUp(username, undefined, k);
|
|
376
|
-
if (signupResult.success) {
|
|
377
|
-
// Immediately login after signup
|
|
378
|
-
const postSignupLogin = await this.core.login(username, "", k);
|
|
379
|
-
if (postSignupLogin.success) {
|
|
380
|
-
// Session is automatically saved by the login method
|
|
381
|
-
postSignupLogin.isNewUser = true;
|
|
382
|
-
// Include SEA pair from core
|
|
383
|
-
if (this.core.user && this.core.user._?.sea) {
|
|
384
|
-
postSignupLogin.sea = this.core.user._.sea;
|
|
385
|
-
}
|
|
386
|
-
return postSignupLogin;
|
|
387
|
-
}
|
|
388
|
-
return {
|
|
389
|
-
success: false,
|
|
390
|
-
error: postSignupLogin.error || "Login failed after successful signup.",
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
// Return the original signup error for other failures
|
|
394
|
-
return signupResult;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|