sunuid-sdk 1.0.51 → 1.0.52
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/README.md +429 -193
- package/docs/INTEGRATION_GUIDE.md +334 -0
- package/docs/SECURITY_GUIDE.md +368 -0
- package/examples/.htaccess.example +187 -0
- package/examples/README.md +192 -0
- package/examples/auto-code.js +234 -0
- package/examples/auto-integration.html +337 -0
- package/examples/basic-usage.php +42 -0
- package/examples/callback-example.html +232 -0
- package/examples/config-example.js +41 -0
- package/examples/demo.html +323 -0
- package/examples/env.example +83 -0
- package/examples/local-qr.php +49 -0
- package/examples/minimal-code.js +147 -0
- package/examples/minimal-integration.html +157 -0
- package/examples/no-loop-example.html +250 -0
- package/examples/partner-name-config.js +123 -0
- package/examples/production-config.js +60 -0
- package/examples/secure-integration-example.js +186 -0
- package/examples/secure-integration.html +410 -0
- package/examples/secure-usage.php +309 -0
- package/examples/simple-kyc.html +95 -0
- package/examples/simple-login.html +96 -0
- package/examples/test-partner-name.html +251 -0
- package/examples/test-production.html +200 -0
- package/examples/universal-kyc.html +199 -0
- package/examples/universal-login.html +148 -0
- package/examples/web-integration.php +138 -0
- package/package.json +24 -10
package/README.md
CHANGED
|
@@ -1,273 +1,509 @@
|
|
|
1
|
-
# SunuID
|
|
1
|
+
# 🔒 SunuID JavaScript SDK - Version 1.0.52
|
|
2
2
|
|
|
3
|
-
SDK
|
|
3
|
+
SDK JavaScript sécurisé pour l'intégration des QR codes d'authentification et KYC SunuID.
|
|
4
4
|
|
|
5
5
|
## 🚀 Installation
|
|
6
6
|
|
|
7
|
-
### Via
|
|
7
|
+
### Via NPM
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
|
|
10
|
+
npm install sunuid-sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
###
|
|
13
|
+
### Via CDN
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<!-- Socket.IO (requis) -->
|
|
17
|
+
<script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>
|
|
18
|
+
|
|
19
|
+
<!-- SunuID SDK -->
|
|
20
|
+
<script src="https://unpkg.com/sunuid-sdk@1.0.52/dist/sunuid-sdk.min.js"></script>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Via Yarn
|
|
14
24
|
|
|
15
25
|
```bash
|
|
16
|
-
|
|
17
|
-
cd php-sdk
|
|
18
|
-
composer install
|
|
26
|
+
yarn add sunuid-sdk
|
|
19
27
|
```
|
|
20
28
|
|
|
21
29
|
## 📋 Prérequis
|
|
22
30
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
31
|
+
- Node.js >= 14.0.0
|
|
32
|
+
- Navigateur moderne avec support ES6+
|
|
33
|
+
- Socket.IO (inclus automatiquement)
|
|
26
34
|
|
|
27
35
|
## 🔧 Configuration
|
|
28
36
|
|
|
29
|
-
### Configuration
|
|
37
|
+
### Configuration Sécurisée (Recommandée)
|
|
30
38
|
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
'
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
```javascript
|
|
40
|
+
// Configuration sécurisée (sans credentials exposés)
|
|
41
|
+
const secureConfig = {
|
|
42
|
+
type: 2, // 1=KYC, 2=AUTH, 3=SIGNATURE
|
|
43
|
+
partnerName: 'MonApplication',
|
|
44
|
+
theme: 'light',
|
|
45
|
+
language: 'fr',
|
|
46
|
+
|
|
47
|
+
// Activer l'initialisation sécurisée
|
|
48
|
+
secureInit: true,
|
|
49
|
+
secureInitUrl: '/secure-init.php', // Votre endpoint sécurisé
|
|
50
|
+
|
|
51
|
+
// Options de sécurité
|
|
52
|
+
enableSecurityLogs: true,
|
|
53
|
+
validateInputs: true,
|
|
54
|
+
maxRetries: 3,
|
|
55
|
+
requestTimeout: 10000,
|
|
56
|
+
tokenMaxAge: 300, // 5 minutes
|
|
57
|
+
|
|
58
|
+
// Callbacks
|
|
59
|
+
onSuccess: (data) => console.log('🎉 Succès:', data),
|
|
60
|
+
onError: (error) => console.error('💥 Erreur:', error),
|
|
61
|
+
onStatusUpdate: (status) => console.log('📊 Statut:', status)
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Créer et initialiser le SDK
|
|
65
|
+
const sunuid = new SunuID(secureConfig);
|
|
66
|
+
await sunuid.init(); // Les credentials sont récupérés automatiquement
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Configuration Traditionnelle (Moins Sécurisée)
|
|
41
70
|
|
|
42
|
-
|
|
43
|
-
|
|
71
|
+
```javascript
|
|
72
|
+
const config = {
|
|
73
|
+
clientId: 'VOTRE_CLIENT_ID',
|
|
74
|
+
secretId: 'VOTRE_SECRET_ID',
|
|
75
|
+
type: 2,
|
|
76
|
+
partnerName: 'MonApplication',
|
|
77
|
+
enableSecurityLogs: true,
|
|
78
|
+
validateInputs: true
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const sunuid = new SunuID(config);
|
|
82
|
+
await sunuid.init();
|
|
44
83
|
```
|
|
45
84
|
|
|
46
|
-
|
|
85
|
+
## 🎯 Utilisation
|
|
47
86
|
|
|
48
|
-
|
|
49
|
-
|--------|------|--------|-------------|
|
|
50
|
-
| `client_id` | string | null | ID client fourni par SunuID |
|
|
51
|
-
| `secret_id` | string | null | Secret ID fourni par SunuID |
|
|
52
|
-
| `type` | int | 2 | Type de service (1=KYC, 2=AUTH, 3=SIGNATURE) |
|
|
53
|
-
| `api_url` | string | https://api.sunuid.fayma.sn | URL de l'API SunuID |
|
|
54
|
-
| `enable_logs` | bool | true | Activer les logs |
|
|
55
|
-
| `log_file` | string | sunuid.log | Fichier de log |
|
|
56
|
-
| `request_timeout` | int | 10 | Timeout des requêtes en secondes |
|
|
57
|
-
| `max_retries` | int | 3 | Nombre de tentatives en cas d'échec |
|
|
58
|
-
| `secure_init` | bool | false | Utiliser l'initialisation sécurisée |
|
|
87
|
+
### Génération de QR Codes
|
|
59
88
|
|
|
60
|
-
|
|
89
|
+
```javascript
|
|
90
|
+
// Générer un QR code d'authentification
|
|
91
|
+
const qrResult = await sunuid.generateQR('qr-container');
|
|
61
92
|
|
|
62
|
-
|
|
93
|
+
console.log('QR Code URL:', qrResult.qrCodeUrl);
|
|
94
|
+
console.log('Session ID:', qrResult.sessionId);
|
|
95
|
+
console.log('Contenu:', qrResult.content);
|
|
63
96
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
$sunuid = new SunuID($config);
|
|
67
|
-
$sunuid->init();
|
|
68
|
-
|
|
69
|
-
// Générer un QR code
|
|
70
|
-
$qrResult = $sunuid->generateQR();
|
|
71
|
-
|
|
72
|
-
echo "QR Code URL: " . $qrResult['qr_code_url'] . "\n";
|
|
73
|
-
echo "Session ID: " . $qrResult['session_id'] . "\n";
|
|
74
|
-
echo "Contenu: " . $qrResult['content'] . "\n";
|
|
75
|
-
|
|
76
|
-
} catch (Exception $e) {
|
|
77
|
-
echo "Erreur: " . $e->getMessage() . "\n";
|
|
78
|
-
}
|
|
79
|
-
```
|
|
97
|
+
// Générer un QR code KYC
|
|
98
|
+
const kycQR = await sunuid.generateKYCQR('qr-container');
|
|
80
99
|
|
|
81
|
-
|
|
100
|
+
// Générer un QR code de signature
|
|
101
|
+
const signatureQR = await sunuid.generateSignatureQR('qr-container');
|
|
82
102
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
'size' => 300,
|
|
88
|
-
'margin' => 10,
|
|
89
|
-
'label' => 'Authentification SunuID'
|
|
90
|
-
]);
|
|
91
|
-
|
|
92
|
-
// L'image est retournée en base64
|
|
93
|
-
$imageData = base64_decode(str_replace('data:image/png;base64,', '', $qrResult['qr_code_url']));
|
|
94
|
-
file_put_contents('qr-code.png', $imageData);
|
|
103
|
+
// Générer un QR code personnalisé
|
|
104
|
+
const customQR = await sunuid.generateCustomQR(1, 'qr-container', {
|
|
105
|
+
label: 'Vérification d\'identité'
|
|
106
|
+
});
|
|
95
107
|
```
|
|
96
108
|
|
|
97
|
-
### Vérification du
|
|
109
|
+
### Vérification du Statut
|
|
98
110
|
|
|
99
|
-
```
|
|
111
|
+
```javascript
|
|
100
112
|
// Vérifier le statut d'un QR code
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
const status = await sunuid.checkQRStatus(qrResult.sessionId);
|
|
114
|
+
console.log('Statut:', status);
|
|
103
115
|
```
|
|
104
116
|
|
|
105
|
-
###
|
|
117
|
+
### Gestion des Callbacks
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
// Générer un état de sécurité
|
|
121
|
+
const state = sunuid.generateState();
|
|
122
|
+
|
|
123
|
+
// Valider un callback reçu
|
|
124
|
+
const callbackData = {
|
|
125
|
+
token: 'jwt_token_here',
|
|
126
|
+
session_id: 'session_123',
|
|
127
|
+
user_id: 123,
|
|
128
|
+
partner_id: 21,
|
|
129
|
+
type: 2,
|
|
130
|
+
timestamp: Date.now(),
|
|
131
|
+
state: state
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
if (sunuid.validateCallback(callbackData)) {
|
|
135
|
+
// Traiter l'authentification
|
|
136
|
+
const authResult = sunuid.processAuthentication(callbackData);
|
|
137
|
+
console.log('Authentification réussie pour l\'utilisateur:', authResult.user_id);
|
|
138
|
+
}
|
|
139
|
+
```
|
|
106
140
|
|
|
107
|
-
|
|
108
|
-
<?php
|
|
109
|
-
require_once 'vendor/autoload.php';
|
|
141
|
+
## 🔒 Sécurité
|
|
110
142
|
|
|
111
|
-
|
|
143
|
+
### Initialisation Sécurisée
|
|
112
144
|
|
|
113
|
-
|
|
114
|
-
'client_id' => 'VOTRE_CLIENT_ID',
|
|
115
|
-
'secret_id' => 'VOTRE_SECRET_ID',
|
|
116
|
-
'type' => 2
|
|
117
|
-
];
|
|
145
|
+
Le SDK supporte l'initialisation sécurisée via un endpoint PHP qui génère des tokens temporaires :
|
|
118
146
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
147
|
+
```php
|
|
148
|
+
// secure-init.php
|
|
149
|
+
<?php
|
|
150
|
+
$SUNUID_CONFIG = [
|
|
151
|
+
'client_id' => $_ENV['SUNUID_CLIENT_ID'],
|
|
152
|
+
'secret_id' => $_ENV['SUNUID_SECRET_ID'],
|
|
153
|
+
'api_url' => 'https://api.sunuid.fayma.sn',
|
|
154
|
+
'token_expiry' => 3600,
|
|
155
|
+
'max_requests_per_token' => 100
|
|
156
|
+
];
|
|
127
157
|
|
|
128
|
-
|
|
129
|
-
<html>
|
|
130
|
-
<head>
|
|
131
|
-
<title>SunuID QR Code</title>
|
|
132
|
-
</head>
|
|
133
|
-
<body>
|
|
134
|
-
<?php if (isset($qrData)): ?>
|
|
135
|
-
<h1>QR Code SunuID</h1>
|
|
136
|
-
<img src="<?php echo htmlspecialchars($qrData['qr_code_url']); ?>"
|
|
137
|
-
alt="QR Code SunuID" />
|
|
138
|
-
<p>Session ID: <?php echo htmlspecialchars($qrData['session_id']); ?></p>
|
|
139
|
-
<?php else: ?>
|
|
140
|
-
<p>Erreur: <?php echo htmlspecialchars($error); ?></p>
|
|
141
|
-
<?php endif; ?>
|
|
142
|
-
</body>
|
|
143
|
-
</html>
|
|
158
|
+
// Le SDK récupère automatiquement les credentials via ce token
|
|
144
159
|
```
|
|
145
160
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
Le SDK utilise des exceptions spécifiques :
|
|
161
|
+
### Logs de Sécurité
|
|
149
162
|
|
|
150
|
-
```
|
|
151
|
-
|
|
163
|
+
```javascript
|
|
164
|
+
// Obtenir les logs de sécurité
|
|
165
|
+
const securityLogs = sunuid.getSecurityLogs();
|
|
166
|
+
securityLogs.forEach(log => {
|
|
167
|
+
console.log('Événement:', log.event, '-', log.timestamp);
|
|
168
|
+
});
|
|
152
169
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
$sunuid->init();
|
|
156
|
-
$qrResult = $sunuid->generateQR();
|
|
157
|
-
|
|
158
|
-
} catch (SunuIDException $e) {
|
|
159
|
-
echo "Erreur SunuID: " . $e->getMessage() . "\n";
|
|
160
|
-
echo "Code d'erreur: " . $e->getErrorCode() . "\n";
|
|
161
|
-
echo "Contexte: " . json_encode($e->getContext()) . "\n";
|
|
162
|
-
|
|
163
|
-
} catch (Exception $e) {
|
|
164
|
-
echo "Erreur générale: " . $e->getMessage() . "\n";
|
|
165
|
-
}
|
|
170
|
+
// Nettoyer les logs
|
|
171
|
+
sunuid.clearSecurityLogs();
|
|
166
172
|
```
|
|
167
173
|
|
|
168
|
-
###
|
|
174
|
+
### Validation des Entrées
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
177
|
+
// La validation est automatiquement activée avec validateInputs: true
|
|
178
|
+
// Le SDK valide :
|
|
179
|
+
// - Format des credentials
|
|
180
|
+
// - Longueur minimale des secrets
|
|
181
|
+
// - Validité des URLs
|
|
182
|
+
// - Types de services autorisés
|
|
183
|
+
```
|
|
169
184
|
|
|
170
|
-
|
|
171
|
-
- `SunuIDException::initializationFailed()` - Échec d'initialisation
|
|
172
|
-
- `SunuIDException::apiError()` - Erreur API
|
|
173
|
-
- `SunuIDException::qrCodeError()` - Erreur QR code
|
|
174
|
-
- `SunuIDException::authenticationError()` - Erreur d'authentification
|
|
175
|
-
- `SunuIDException::networkError()` - Erreur réseau
|
|
185
|
+
## 🌐 WebSocket
|
|
176
186
|
|
|
177
|
-
|
|
187
|
+
Le SDK inclut une gestion complète des WebSockets pour les mises à jour en temps réel :
|
|
178
188
|
|
|
179
|
-
|
|
189
|
+
```javascript
|
|
190
|
+
// Statut de la connexion WebSocket
|
|
191
|
+
const wsStatus = sunuid.getWebSocketStatus();
|
|
192
|
+
console.log('WebSocket:', wsStatus); // 'connected', 'disconnected', 'not_initialized'
|
|
180
193
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
$logger = $sunuid->getLogger();
|
|
194
|
+
// Émettre un événement WebSocket
|
|
195
|
+
sunuid.emitWebSocketEvent('custom_event', { data: 'value' });
|
|
184
196
|
|
|
185
|
-
//
|
|
186
|
-
|
|
197
|
+
// Forcer l'initialisation WebSocket
|
|
198
|
+
sunuid.forceWebSocketInit();
|
|
187
199
|
```
|
|
188
200
|
|
|
189
|
-
|
|
201
|
+
### Événements WebSocket
|
|
190
202
|
|
|
191
|
-
|
|
203
|
+
Le SDK écoute automatiquement ces événements :
|
|
192
204
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
205
|
+
- `qr_status_update` - Mise à jour du statut QR
|
|
206
|
+
- `qr_scan_success` - Scan QR réussi
|
|
207
|
+
- `qr_expired` - QR expiré
|
|
208
|
+
- `qr_scan_initiated` - Scan QR initié
|
|
196
209
|
|
|
197
|
-
|
|
210
|
+
## 🛠️ Gestion d'Erreurs
|
|
198
211
|
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
|
|
212
|
+
```javascript
|
|
213
|
+
try {
|
|
214
|
+
const sunuid = new SunuID(config);
|
|
215
|
+
await sunuid.init();
|
|
216
|
+
const qrResult = await sunuid.generateQR('qr-container');
|
|
217
|
+
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error('Erreur SunuID:', error.message);
|
|
220
|
+
|
|
221
|
+
if (error.name === 'SunuIDException') {
|
|
222
|
+
console.error('Code:', error.code);
|
|
223
|
+
console.error('Contexte:', error.context);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
202
227
|
|
|
203
|
-
|
|
204
|
-
php examples/local-qr.php
|
|
228
|
+
## 📊 Informations et Statut
|
|
205
229
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
230
|
+
```javascript
|
|
231
|
+
// Obtenir la configuration
|
|
232
|
+
const config = sunuid.getConfig();
|
|
209
233
|
|
|
210
|
-
|
|
234
|
+
// Obtenir les informations du partenaire
|
|
235
|
+
const partnerInfo = sunuid.getPartnerInfo();
|
|
211
236
|
|
|
212
|
-
|
|
237
|
+
// Vérifier si le SDK est initialisé
|
|
238
|
+
if (sunuid.isInitialized) {
|
|
239
|
+
console.log('SDK prêt à l\'utilisation');
|
|
240
|
+
}
|
|
213
241
|
|
|
214
|
-
|
|
215
|
-
|
|
242
|
+
// Obtenir les logs de sécurité
|
|
243
|
+
const securityLogs = sunuid.getSecurityLogs();
|
|
244
|
+
```
|
|
216
245
|
|
|
217
|
-
|
|
218
|
-
Initialise le SDK. Doit être appelé avant toute autre méthode.
|
|
246
|
+
## 🔧 Configuration Avancée
|
|
219
247
|
|
|
220
|
-
|
|
221
|
-
Génère un QR code via l'API SunuID.
|
|
248
|
+
### Variables d'Environnement
|
|
222
249
|
|
|
223
|
-
|
|
224
|
-
|
|
250
|
+
```javascript
|
|
251
|
+
// En production, utilisez des variables d'environnement
|
|
252
|
+
const config = {
|
|
253
|
+
type: 2,
|
|
254
|
+
partnerName: process.env.SUNUID_PARTNER_NAME,
|
|
255
|
+
secureInit: true,
|
|
256
|
+
secureInitUrl: process.env.SUNUID_SECURE_INIT_URL,
|
|
257
|
+
enableSecurityLogs: true,
|
|
258
|
+
validateInputs: true
|
|
259
|
+
};
|
|
260
|
+
```
|
|
225
261
|
|
|
226
|
-
|
|
227
|
-
|
|
262
|
+
### Configuration de Production
|
|
263
|
+
|
|
264
|
+
```javascript
|
|
265
|
+
const prodConfig = {
|
|
266
|
+
type: 2,
|
|
267
|
+
partnerName: 'AppProduction',
|
|
268
|
+
secureInit: true,
|
|
269
|
+
secureInitUrl: '/api/secure-init',
|
|
270
|
+
enableSecurityLogs: true,
|
|
271
|
+
validateInputs: true,
|
|
272
|
+
requestTimeout: 15000,
|
|
273
|
+
maxRetries: 5,
|
|
274
|
+
tokenMaxAge: 180 // 3 minutes
|
|
275
|
+
};
|
|
276
|
+
```
|
|
228
277
|
|
|
229
|
-
|
|
278
|
+
## 📝 Exemples Complets
|
|
230
279
|
|
|
231
|
-
|
|
232
|
-
Retourne la configuration actuelle.
|
|
280
|
+
### Exemple d'Intégration Web
|
|
233
281
|
|
|
234
|
-
|
|
235
|
-
|
|
282
|
+
```html
|
|
283
|
+
<!DOCTYPE html>
|
|
284
|
+
<html>
|
|
285
|
+
<head>
|
|
286
|
+
<title>SunuID SDK - Intégration Sécurisée</title>
|
|
287
|
+
</head>
|
|
288
|
+
<body>
|
|
289
|
+
<div id="qr-container">
|
|
290
|
+
<!-- Le QR code sera affiché ici -->
|
|
291
|
+
</div>
|
|
292
|
+
|
|
293
|
+
<button onclick="initSunuID()">Générer QR Code</button>
|
|
294
|
+
|
|
295
|
+
<script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>
|
|
296
|
+
<script src="https://unpkg.com/sunuid-sdk@2.0.0/dist/sunuid-sdk.min.js"></script>
|
|
297
|
+
|
|
298
|
+
<script>
|
|
299
|
+
const config = {
|
|
300
|
+
type: 2,
|
|
301
|
+
partnerName: 'MonApp',
|
|
302
|
+
secureInit: true,
|
|
303
|
+
secureInitUrl: '/secure-init.php',
|
|
304
|
+
onSuccess: (data) => {
|
|
305
|
+
console.log('🎉 Authentification réussie:', data);
|
|
306
|
+
document.getElementById('qr-container').innerHTML =
|
|
307
|
+
'<h2>✅ Authentification réussie !</h2>';
|
|
308
|
+
},
|
|
309
|
+
onError: (error) => {
|
|
310
|
+
console.error('💥 Erreur:', error);
|
|
311
|
+
document.getElementById('qr-container').innerHTML =
|
|
312
|
+
'<h2>❌ Erreur: ' + error.message + '</h2>';
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
async function initSunuID() {
|
|
317
|
+
try {
|
|
318
|
+
const sunuid = new SunuID(config);
|
|
319
|
+
await sunuid.init();
|
|
320
|
+
await sunuid.generateQR('qr-container');
|
|
321
|
+
} catch (error) {
|
|
322
|
+
console.error('Erreur:', error);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
</script>
|
|
326
|
+
</body>
|
|
327
|
+
</html>
|
|
328
|
+
```
|
|
236
329
|
|
|
237
|
-
|
|
238
|
-
Vérifie si le SDK est initialisé.
|
|
330
|
+
### Exemple avec React
|
|
239
331
|
|
|
240
|
-
|
|
241
|
-
|
|
332
|
+
```jsx
|
|
333
|
+
import React, { useEffect, useState } from 'react';
|
|
334
|
+
import { SunuID } from 'sunuid-sdk';
|
|
242
335
|
|
|
243
|
-
|
|
336
|
+
function SunuIDComponent() {
|
|
337
|
+
const [qrUrl, setQrUrl] = useState(null);
|
|
338
|
+
const [error, setError] = useState(null);
|
|
339
|
+
|
|
340
|
+
useEffect(() => {
|
|
341
|
+
const initSDK = async () => {
|
|
342
|
+
const config = {
|
|
343
|
+
type: 2,
|
|
344
|
+
partnerName: 'ReactApp',
|
|
345
|
+
secureInit: true,
|
|
346
|
+
secureInitUrl: '/api/secure-init',
|
|
347
|
+
onSuccess: (data) => {
|
|
348
|
+
console.log('Authentification réussie:', data);
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
try {
|
|
353
|
+
const sunuid = new SunuID(config);
|
|
354
|
+
await sunuid.init();
|
|
355
|
+
const result = await sunuid.generateQR('qr-container');
|
|
356
|
+
setQrUrl(result.qrCodeUrl);
|
|
357
|
+
} catch (err) {
|
|
358
|
+
setError(err.message);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
initSDK();
|
|
363
|
+
}, []);
|
|
364
|
+
|
|
365
|
+
if (error) return <div>Erreur: {error}</div>;
|
|
366
|
+
if (!qrUrl) return <div>Chargement...</div>;
|
|
367
|
+
|
|
368
|
+
return (
|
|
369
|
+
<div>
|
|
370
|
+
<h2>QR Code SunuID</h2>
|
|
371
|
+
<img src={qrUrl} alt="QR Code" />
|
|
372
|
+
</div>
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
```
|
|
244
376
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
377
|
+
### Exemple avec Vue.js
|
|
378
|
+
|
|
379
|
+
```vue
|
|
380
|
+
<template>
|
|
381
|
+
<div>
|
|
382
|
+
<h2>QR Code SunuID</h2>
|
|
383
|
+
<div v-if="qrUrl">
|
|
384
|
+
<img :src="qrUrl" alt="QR Code" />
|
|
385
|
+
</div>
|
|
386
|
+
<div v-else-if="error">
|
|
387
|
+
<p>Erreur: {{ error }}</p>
|
|
388
|
+
</div>
|
|
389
|
+
<div v-else>
|
|
390
|
+
<p>Chargement...</p>
|
|
391
|
+
</div>
|
|
392
|
+
</div>
|
|
393
|
+
</template>
|
|
394
|
+
|
|
395
|
+
<script>
|
|
396
|
+
import { SunuID } from 'sunuid-sdk';
|
|
397
|
+
|
|
398
|
+
export default {
|
|
399
|
+
data() {
|
|
400
|
+
return {
|
|
401
|
+
qrUrl: null,
|
|
402
|
+
error: null
|
|
403
|
+
};
|
|
404
|
+
},
|
|
405
|
+
async mounted() {
|
|
406
|
+
const config = {
|
|
407
|
+
type: 2,
|
|
408
|
+
partnerName: 'VueApp',
|
|
409
|
+
secureInit: true,
|
|
410
|
+
secureInitUrl: '/api/secure-init',
|
|
411
|
+
onSuccess: (data) => {
|
|
412
|
+
console.log('Authentification réussie:', data);
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
try {
|
|
417
|
+
const sunuid = new SunuID(config);
|
|
418
|
+
await sunuid.init();
|
|
419
|
+
const result = await sunuid.generateQR('qr-container');
|
|
420
|
+
this.qrUrl = result.qrCodeUrl;
|
|
421
|
+
} catch (err) {
|
|
422
|
+
this.error = err.message;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
</script>
|
|
427
|
+
```
|
|
250
428
|
|
|
251
|
-
##
|
|
429
|
+
## 🧪 Tests
|
|
252
430
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
431
|
+
```bash
|
|
432
|
+
# Exécuter les tests
|
|
433
|
+
npm test
|
|
256
434
|
|
|
257
|
-
|
|
435
|
+
# Test avec couverture
|
|
436
|
+
npm run test:coverage
|
|
258
437
|
|
|
259
|
-
|
|
438
|
+
# Test de sécurité
|
|
439
|
+
npm run security-check
|
|
440
|
+
```
|
|
260
441
|
|
|
261
|
-
##
|
|
442
|
+
## 📚 Documentation
|
|
443
|
+
|
|
444
|
+
- [Guide de Sécurisation](docs/SECURITY_GUIDE.md)
|
|
445
|
+
- [Guide d'Intégration](docs/INTEGRATION_GUIDE.md)
|
|
446
|
+
- [Exemples d'Utilisation](examples/)
|
|
447
|
+
|
|
448
|
+
## 🔄 Migration depuis la Version 1.x
|
|
449
|
+
|
|
450
|
+
### Changements Majeurs
|
|
451
|
+
|
|
452
|
+
1. **Nouvelle Configuration Sécurisée**
|
|
453
|
+
```javascript
|
|
454
|
+
// Avant (v1.x)
|
|
455
|
+
const config = { clientId: '...', secretId: '...' };
|
|
456
|
+
|
|
457
|
+
// Après (v2.0)
|
|
458
|
+
const config = { secureInit: true, secureInitUrl: '/secure-init.php' };
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
2. **Nouvelles Méthodes**
|
|
462
|
+
```javascript
|
|
463
|
+
// Nouvelles méthodes disponibles
|
|
464
|
+
sunuid.getSecurityLogs();
|
|
465
|
+
sunuid.clearSecurityLogs();
|
|
466
|
+
sunuid.generateState();
|
|
467
|
+
sunuid.validateCallback(data);
|
|
468
|
+
sunuid.processAuthentication(data);
|
|
469
|
+
sunuid.getWebSocketStatus();
|
|
470
|
+
sunuid.emitWebSocketEvent(event, data);
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
3. **Gestion d'Erreurs Améliorée**
|
|
474
|
+
```javascript
|
|
475
|
+
// Avant
|
|
476
|
+
catch (error)
|
|
477
|
+
|
|
478
|
+
// Après
|
|
479
|
+
catch (error) {
|
|
480
|
+
if (error.name === 'SunuIDException') {
|
|
481
|
+
console.error('Code:', error.code);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
## 🛡️ Bonnes Pratiques
|
|
487
|
+
|
|
488
|
+
1. **Utilisez toujours l'initialisation sécurisée** en production
|
|
489
|
+
2. **Stockez les credentials côté serveur uniquement**
|
|
490
|
+
3. **Activez les logs de sécurité** pour le monitoring
|
|
491
|
+
4. **Validez tous les callbacks** reçus
|
|
492
|
+
5. **Gérez les erreurs** avec try/catch
|
|
493
|
+
6. **Surveillez les logs** régulièrement
|
|
494
|
+
7. **Changez vos credentials** périodiquement
|
|
495
|
+
8. **Utilisez HTTPS** en production
|
|
496
|
+
|
|
497
|
+
## 📞 Support
|
|
498
|
+
|
|
499
|
+
- **Documentation** : https://sunuid.fayma.sn/docs
|
|
500
|
+
- **Issues** : https://github.com/sunuid/sunuid-sdk/issues
|
|
501
|
+
- **Email** : contact@sunuid.fayma.sn
|
|
262
502
|
|
|
263
|
-
|
|
503
|
+
## 📄 Licence
|
|
264
504
|
|
|
265
|
-
|
|
266
|
-
2. Créer une branche pour votre fonctionnalité
|
|
267
|
-
3. Commiter vos changements
|
|
268
|
-
4. Pousser vers la branche
|
|
269
|
-
5. Ouvrir une Pull Request
|
|
505
|
+
MIT License - voir le fichier [LICENSE](LICENSE) pour plus de détails.
|
|
270
506
|
|
|
271
|
-
|
|
507
|
+
---
|
|
272
508
|
|
|
273
|
-
|
|
509
|
+
**⚠️ Important** : La sécurité de vos credentials est de votre responsabilité. Suivez toujours les bonnes pratiques et testez votre implémentation avant la mise en production.
|