sunuid-sdk 1.0.40 → 1.0.41
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/dist/sunuid-sdk.esm.js +229 -14
- package/dist/sunuid-sdk.esm.js.map +1 -1
- package/dist/sunuid-sdk.js +229 -14
- package/dist/sunuid-sdk.js.map +1 -1
- package/dist/sunuid-sdk.min.js +3 -3
- package/dist/sunuid-sdk.min.js.map +1 -1
- package/package.json +1 -1
package/dist/sunuid-sdk.esm.js
CHANGED
|
@@ -311,7 +311,15 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
311
311
|
token: null,
|
|
312
312
|
// Configuration pour forcer l'utilisation du serveur distant
|
|
313
313
|
forceRemoteServer: true,
|
|
314
|
-
useLocalFallback: false
|
|
314
|
+
useLocalFallback: false,
|
|
315
|
+
// Nouvelles options pour les callbacks
|
|
316
|
+
redirectAfterSuccess: null,
|
|
317
|
+
verifySignature: false,
|
|
318
|
+
tokenMaxAge: 300,
|
|
319
|
+
// 5 minutes par défaut
|
|
320
|
+
onAuthenticationSuccess: null,
|
|
321
|
+
onAuthenticationError: null,
|
|
322
|
+
state: null
|
|
315
323
|
};
|
|
316
324
|
|
|
317
325
|
/**
|
|
@@ -345,21 +353,28 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
345
353
|
while (1) switch (_context.p = _context.n) {
|
|
346
354
|
case 0:
|
|
347
355
|
_context.p = 0;
|
|
356
|
+
if (!this.handleCallback()) {
|
|
357
|
+
_context.n = 1;
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
console.log('✅ Callback traité, initialisation terminée');
|
|
361
|
+
return _context.a(2);
|
|
362
|
+
case 1:
|
|
348
363
|
if (!this.config.secureInit) {
|
|
349
|
-
_context.n =
|
|
364
|
+
_context.n = 3;
|
|
350
365
|
break;
|
|
351
366
|
}
|
|
352
|
-
_context.n =
|
|
367
|
+
_context.n = 2;
|
|
353
368
|
return this.secureInit();
|
|
354
|
-
case 1:
|
|
355
|
-
_context.n = 3;
|
|
356
|
-
break;
|
|
357
369
|
case 2:
|
|
370
|
+
_context.n = 4;
|
|
371
|
+
break;
|
|
372
|
+
case 3:
|
|
358
373
|
// Validation sécurisée des paramètres
|
|
359
374
|
if (this.config.validateInputs) {
|
|
360
375
|
this.validateSecurityParams();
|
|
361
376
|
}
|
|
362
|
-
case
|
|
377
|
+
case 4:
|
|
363
378
|
// Log de sécurité pour l'initialisation
|
|
364
379
|
this.logSecurityEvent('SDK_INIT_START', {
|
|
365
380
|
apiUrl: this.config.apiUrl,
|
|
@@ -368,9 +383,9 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
368
383
|
});
|
|
369
384
|
|
|
370
385
|
// Récupérer les informations du partenaire depuis l'API
|
|
371
|
-
_context.n =
|
|
386
|
+
_context.n = 5;
|
|
372
387
|
return this.fetchPartnerInfo();
|
|
373
|
-
case
|
|
388
|
+
case 5:
|
|
374
389
|
// Obscurcir les credentials dans les logs
|
|
375
390
|
this.obfuscateCredentials();
|
|
376
391
|
this.isInitialized = true;
|
|
@@ -388,19 +403,19 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
388
403
|
|
|
389
404
|
// Initialiser la connexion WebSocket
|
|
390
405
|
this.initWebSocket();
|
|
391
|
-
_context.n =
|
|
406
|
+
_context.n = 7;
|
|
392
407
|
break;
|
|
393
|
-
case
|
|
394
|
-
_context.p =
|
|
408
|
+
case 6:
|
|
409
|
+
_context.p = 6;
|
|
395
410
|
_t = _context.v;
|
|
396
411
|
this.logSecurityEvent('SDK_INIT_ERROR', {
|
|
397
412
|
error: _t.message
|
|
398
413
|
});
|
|
399
414
|
throw _t;
|
|
400
|
-
case
|
|
415
|
+
case 7:
|
|
401
416
|
return _context.a(2);
|
|
402
417
|
}
|
|
403
|
-
}, _callee, this, [[0,
|
|
418
|
+
}, _callee, this, [[0, 6]]);
|
|
404
419
|
}));
|
|
405
420
|
function init() {
|
|
406
421
|
return _init.apply(this, arguments);
|
|
@@ -2509,6 +2524,206 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
2509
2524
|
container.innerHTML = "\n <div style=\"\n text-align: center;\n padding: 40px 20px;\n background: #f8f9fa;\n border: 2px solid #007bff;\n border-radius: 10px;\n color: #007bff;\n font-family: Arial, sans-serif;\n \">\n <div style=\"\n width: 60px;\n height: 60px;\n border: 4px solid #e3f2fd;\n border-top: 4px solid #007bff;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n margin: 0 auto 20px auto;\n \"></div>\n <h3 style=\"margin: 0 0 10px 0; color: #007bff;\">\uD83D\uDD0D Scan en cours...</h3>\n <p style=\"margin: 0; font-size: 14px;\">\n Veuillez patienter pendant la v\xE9rification de votre identit\xE9.\n </p>\n <div style=\"margin-top: 15px; font-size: 12px; color: #6c757d;\">\n \u23F1\uFE0F Traitement en cours...\n </div>\n </div>\n <style>\n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n </style>\n ";
|
|
2510
2525
|
console.log('✅ Loader affiché avec succès');
|
|
2511
2526
|
}
|
|
2527
|
+
|
|
2528
|
+
/**
|
|
2529
|
+
* Gérer le callback SunuID
|
|
2530
|
+
*/
|
|
2531
|
+
}, {
|
|
2532
|
+
key: "handleCallback",
|
|
2533
|
+
value: function handleCallback() {
|
|
2534
|
+
var urlParams = new URLSearchParams(window.location.search);
|
|
2535
|
+
|
|
2536
|
+
// Vérifier si c'est un callback SunuID
|
|
2537
|
+
if (urlParams.has('token') && urlParams.has('session_id')) {
|
|
2538
|
+
console.log('🔗 Callback SunuID détecté');
|
|
2539
|
+
|
|
2540
|
+
// Récupérer les paramètres
|
|
2541
|
+
var callbackData = {
|
|
2542
|
+
token: urlParams.get('token'),
|
|
2543
|
+
state: urlParams.get('state'),
|
|
2544
|
+
session_id: urlParams.get('session_id'),
|
|
2545
|
+
user_id: urlParams.get('user_id'),
|
|
2546
|
+
partner_id: urlParams.get('partner_id'),
|
|
2547
|
+
type: urlParams.get('type'),
|
|
2548
|
+
timestamp: urlParams.get('timestamp'),
|
|
2549
|
+
signature: urlParams.get('signature')
|
|
2550
|
+
};
|
|
2551
|
+
console.log('📋 Données callback:', callbackData);
|
|
2552
|
+
|
|
2553
|
+
// Valider le callback
|
|
2554
|
+
this.validateCallback(callbackData);
|
|
2555
|
+
|
|
2556
|
+
// Traiter l'authentification
|
|
2557
|
+
this.processAuthentication(callbackData);
|
|
2558
|
+
return true;
|
|
2559
|
+
}
|
|
2560
|
+
return false;
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
/**
|
|
2564
|
+
* Valider le callback
|
|
2565
|
+
*/
|
|
2566
|
+
}, {
|
|
2567
|
+
key: "validateCallback",
|
|
2568
|
+
value: function validateCallback(data) {
|
|
2569
|
+
console.log('🔒 Validation du callback...');
|
|
2570
|
+
|
|
2571
|
+
// Vérifier l'état de sécurité
|
|
2572
|
+
if (data.state && data.state !== this.config.state) {
|
|
2573
|
+
console.error('❌ État de sécurité invalide');
|
|
2574
|
+
throw new Error('État de sécurité invalide');
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2577
|
+
// Vérifier la signature (si configurée)
|
|
2578
|
+
if (data.signature && this.config.verifySignature) {
|
|
2579
|
+
if (!this.verifySignature(data)) {
|
|
2580
|
+
console.error('❌ Signature invalide');
|
|
2581
|
+
throw new Error('Signature invalide');
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
// Vérifier l'expiration
|
|
2586
|
+
if (data.timestamp && this.isExpired(data.timestamp)) {
|
|
2587
|
+
console.error('❌ Token expiré');
|
|
2588
|
+
throw new Error('Token expiré');
|
|
2589
|
+
}
|
|
2590
|
+
console.log('✅ Callback validé avec succès');
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
/**
|
|
2594
|
+
* Traiter l'authentification
|
|
2595
|
+
*/
|
|
2596
|
+
}, {
|
|
2597
|
+
key: "processAuthentication",
|
|
2598
|
+
value: function processAuthentication(data) {
|
|
2599
|
+
console.log('🔐 Traitement de l\'authentification...');
|
|
2600
|
+
try {
|
|
2601
|
+
// Décoder le JWT token
|
|
2602
|
+
var decodedToken = this.decodeJWT(data.token);
|
|
2603
|
+
|
|
2604
|
+
// Vérifier les données utilisateur
|
|
2605
|
+
var userData = {
|
|
2606
|
+
user_id: decodedToken.user_id || data.user_id,
|
|
2607
|
+
session_id: decodedToken.session_id || data.session_id,
|
|
2608
|
+
partner_id: decodedToken.partner_id || data.partner_id,
|
|
2609
|
+
type: decodedToken.type || data.type,
|
|
2610
|
+
iat: decodedToken.iat,
|
|
2611
|
+
exp: decodedToken.exp
|
|
2612
|
+
};
|
|
2613
|
+
console.log('👤 Données utilisateur:', userData);
|
|
2614
|
+
|
|
2615
|
+
// Émettre l'événement de succès
|
|
2616
|
+
this.emitWebSocketEvent('authentication_success', {
|
|
2617
|
+
userData: userData,
|
|
2618
|
+
callbackData: data,
|
|
2619
|
+
timestamp: Date.now()
|
|
2620
|
+
});
|
|
2621
|
+
|
|
2622
|
+
// Appeler le callback de succès
|
|
2623
|
+
if (this.config.onAuthenticationSuccess) {
|
|
2624
|
+
this.config.onAuthenticationSuccess(userData, data);
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
// Rediriger si configuré
|
|
2628
|
+
if (this.config.redirectAfterSuccess) {
|
|
2629
|
+
this.redirectAfterSuccess(userData);
|
|
2630
|
+
}
|
|
2631
|
+
console.log('✅ Authentification traitée avec succès');
|
|
2632
|
+
} catch (error) {
|
|
2633
|
+
console.error('❌ Erreur lors du traitement:', error);
|
|
2634
|
+
|
|
2635
|
+
// Appeler le callback d'erreur
|
|
2636
|
+
if (this.config.onAuthenticationError) {
|
|
2637
|
+
this.config.onAuthenticationError(error, data);
|
|
2638
|
+
}
|
|
2639
|
+
throw error;
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
|
|
2643
|
+
/**
|
|
2644
|
+
* Décoder un JWT token
|
|
2645
|
+
*/
|
|
2646
|
+
}, {
|
|
2647
|
+
key: "decodeJWT",
|
|
2648
|
+
value: function decodeJWT(token) {
|
|
2649
|
+
try {
|
|
2650
|
+
// Décodage simple du JWT (sans vérification de signature)
|
|
2651
|
+
var parts = token.split('.');
|
|
2652
|
+
if (parts.length !== 3) {
|
|
2653
|
+
throw new Error('Format JWT invalide');
|
|
2654
|
+
}
|
|
2655
|
+
var payload = parts[1];
|
|
2656
|
+
var decoded = JSON.parse(atob(payload));
|
|
2657
|
+
return decoded;
|
|
2658
|
+
} catch (error) {
|
|
2659
|
+
console.error('❌ Erreur décodage JWT:', error);
|
|
2660
|
+
throw new Error('Token JWT invalide');
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
/**
|
|
2665
|
+
* Vérifier la signature
|
|
2666
|
+
*/
|
|
2667
|
+
}, {
|
|
2668
|
+
key: "verifySignature",
|
|
2669
|
+
value: function verifySignature(data) {
|
|
2670
|
+
// Implémentation basique - à adapter selon vos besoins
|
|
2671
|
+
var expectedSignature = this.generateSignature(data);
|
|
2672
|
+
return data.signature === expectedSignature;
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
/**
|
|
2676
|
+
* Générer une signature
|
|
2677
|
+
*/
|
|
2678
|
+
}, {
|
|
2679
|
+
key: "generateSignature",
|
|
2680
|
+
value: function generateSignature(data) {
|
|
2681
|
+
// Implémentation basique - à adapter selon vos besoins
|
|
2682
|
+
var payload = "".concat(data.token, ".").concat(data.state, ".").concat(data.session_id, ".").concat(data.timestamp);
|
|
2683
|
+
return btoa(payload).slice(0, 12); // Signature simplifiée
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
/**
|
|
2687
|
+
* Vérifier l'expiration
|
|
2688
|
+
*/
|
|
2689
|
+
}, {
|
|
2690
|
+
key: "isExpired",
|
|
2691
|
+
value: function isExpired(timestamp) {
|
|
2692
|
+
var currentTime = Math.floor(Date.now() / 1000);
|
|
2693
|
+
var tokenTime = parseInt(timestamp);
|
|
2694
|
+
var maxAge = this.config.tokenMaxAge || 300; // 5 minutes par défaut
|
|
2695
|
+
|
|
2696
|
+
return currentTime - tokenTime > maxAge;
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
/**
|
|
2700
|
+
* Rediriger après succès
|
|
2701
|
+
*/
|
|
2702
|
+
}, {
|
|
2703
|
+
key: "redirectAfterSuccess",
|
|
2704
|
+
value: function redirectAfterSuccess(userData) {
|
|
2705
|
+
var redirectUrl = this.config.redirectAfterSuccess;
|
|
2706
|
+
|
|
2707
|
+
// Remplacer les variables dans l'URL
|
|
2708
|
+
redirectUrl = redirectUrl.replace('{user_id}', userData.user_id).replace('{session_id}', userData.session_id).replace('{partner_id}', userData.partner_id).replace('{type}', userData.type);
|
|
2709
|
+
console.log('🔄 Redirection vers:', redirectUrl);
|
|
2710
|
+
|
|
2711
|
+
// Redirection avec délai pour permettre les callbacks
|
|
2712
|
+
setTimeout(function () {
|
|
2713
|
+
window.location.href = redirectUrl;
|
|
2714
|
+
}, 100);
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
/**
|
|
2718
|
+
* Générer un état de sécurité
|
|
2719
|
+
*/
|
|
2720
|
+
}, {
|
|
2721
|
+
key: "generateState",
|
|
2722
|
+
value: function generateState() {
|
|
2723
|
+
var state = 'sunuid_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
|
|
2724
|
+
this.config.state = state;
|
|
2725
|
+
return state;
|
|
2726
|
+
}
|
|
2512
2727
|
}]);
|
|
2513
2728
|
}(); // Exposer la classe globalement
|
|
2514
2729
|
window.SunuID = SunuID;
|