authix-python-sdk 1.0.0__py3-none-any.whl

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.
authix/handlers.py ADDED
@@ -0,0 +1,570 @@
1
+ """
2
+ Authix API Handlers
3
+ Individual handlers for different Authix API endpoints
4
+ """
5
+
6
+ from typing import Dict, Any, List, Optional
7
+ from .client import APIClient
8
+
9
+
10
+ class BaseHandler:
11
+ """Base class for all API handlers"""
12
+
13
+ def __init__(self, client: APIClient):
14
+ """
15
+ Initialize handler with API client
16
+
17
+ Args:
18
+ client: Authix API client
19
+ """
20
+ self.client = client
21
+
22
+
23
+ class AuthHandler(BaseHandler):
24
+ """Handler for authentication endpoints"""
25
+
26
+ async def register(self,
27
+ username: str,
28
+ password: str,
29
+ license_key: str,
30
+ hwid: str,
31
+ app_id: str,
32
+ app_name: str) -> Dict[str, Any]:
33
+ """
34
+ Register a new user
35
+
36
+ Args:
37
+ username: Username for the new user
38
+ password: Password for the new user
39
+ license_key: License key for activation
40
+ hwid: Hardware ID for device binding
41
+ app_id: Application ID
42
+ app_name: Application name
43
+
44
+ Returns:
45
+ Registration result with user data and tokens
46
+ """
47
+ data = {
48
+ 'username': username,
49
+ 'password': password,
50
+ 'license_key': license_key,
51
+ 'hwid': hwid,
52
+ 'app_id': app_id,
53
+ 'app_name': app_name
54
+ }
55
+ return await self.client.post('/auth/register', data)
56
+
57
+ async def login(self,
58
+ username: str,
59
+ password: str,
60
+ hwid: str,
61
+ app_id: str,
62
+ app_name: str) -> Dict[str, Any]:
63
+ """
64
+ Login user
65
+
66
+ Args:
67
+ username: User username
68
+ password: User password
69
+ hwid: Hardware ID for device verification
70
+ app_id: Application ID
71
+ app_name: Application name
72
+
73
+ Returns:
74
+ Login result with authentication tokens
75
+ """
76
+ data = {
77
+ 'username': username,
78
+ 'password': password,
79
+ 'hwid': hwid,
80
+ 'app_id': app_id,
81
+ 'app_name': app_name
82
+ }
83
+ return await self.client.post('/auth/login', data)
84
+
85
+ async def logout(self, token: str) -> Dict[str, Any]:
86
+ """
87
+ Logout user and invalidate token
88
+
89
+ Args:
90
+ token: Authentication token to invalidate
91
+
92
+ Returns:
93
+ Logout result
94
+ """
95
+ data = {'token': token}
96
+ return await self.client.post('/auth/logout', data)
97
+
98
+ async def refresh_token(self, refresh_token: str) -> Dict[str, Any]:
99
+ """
100
+ Refresh authentication token
101
+
102
+ Args:
103
+ refresh_token: Refresh token
104
+
105
+ Returns:
106
+ New authentication tokens
107
+ """
108
+ data = {'refresh_token': refresh_token}
109
+ return await self.client.post('/auth/refresh', data)
110
+
111
+ async def verify_token(self, token: str) -> Dict[str, Any]:
112
+ """
113
+ Verify authentication token
114
+
115
+ Args:
116
+ token: Authentication token to verify
117
+
118
+ Returns:
119
+ Token verification result with user data
120
+ """
121
+ data = {'token': token}
122
+ return await self.client.post('/auth/verify', data)
123
+
124
+
125
+ class AppsHandler(BaseHandler):
126
+ """Handler for application management endpoints"""
127
+
128
+ async def get_apps(self) -> List[Dict[str, Any]]:
129
+ """
130
+ Get all applications
131
+
132
+ Returns:
133
+ List of applications
134
+ """
135
+ result = await self.client.get('/apps')
136
+ return result.get('apps', [])
137
+
138
+ async def create_app(self, name: str, description: str = None) -> Dict[str, Any]:
139
+ """
140
+ Create new application
141
+
142
+ Args:
143
+ name: Application name
144
+ description: Application description
145
+
146
+ Returns:
147
+ Created application data
148
+ """
149
+ data = {'name': name}
150
+ if description:
151
+ data['description'] = description
152
+
153
+ return await self.client.post('/apps', data)
154
+
155
+ async def get_app_details(self, app_id: str) -> Dict[str, Any]:
156
+ """
157
+ Get application details
158
+
159
+ Args:
160
+ app_id: Application ID
161
+
162
+ Returns:
163
+ Application details
164
+ """
165
+ return await self.client.get(f'/apps/{app_id}')
166
+
167
+ async def update_app(self, app_id: str, name: str = None, description: str = None) -> Dict[str, Any]:
168
+ """
169
+ Update application
170
+
171
+ Args:
172
+ app_id: Application ID
173
+ name: New application name
174
+ description: New application description
175
+
176
+ Returns:
177
+ Updated application data
178
+ """
179
+ data = {}
180
+ if name:
181
+ data['name'] = name
182
+ if description:
183
+ data['description'] = description
184
+
185
+ return await self.client.put(f'/apps/{app_id}', data)
186
+
187
+ async def delete_app(self, app_id: str) -> Dict[str, Any]:
188
+ """
189
+ Delete application
190
+
191
+ Args:
192
+ app_id: Application ID
193
+
194
+ Returns:
195
+ Deletion result
196
+ """
197
+ return await self.client.delete(f'/apps/{app_id}')
198
+
199
+ async def reset_hwid(self, app_id: str, username: str, password: str, license_key: str) -> Dict[str, Any]:
200
+ """
201
+ Reset user HWID
202
+
203
+ Args:
204
+ app_id: Application ID
205
+ username: Username
206
+ password: User password
207
+ license_key: License key for verification
208
+
209
+ Returns:
210
+ HWID reset result
211
+ """
212
+ data = {
213
+ 'username': username,
214
+ 'password': password,
215
+ 'license_key': license_key
216
+ }
217
+ return await self.client.post(f'/apps/{app_id}/reset-hwid', data)
218
+
219
+
220
+ class LicensesHandler(BaseHandler):
221
+ """Handler for license management endpoints"""
222
+
223
+ async def create_license(self, app_id: str, days: int, max_hwids: int = 3) -> Dict[str, Any]:
224
+ """
225
+ Create new license
226
+
227
+ Args:
228
+ app_id: Application ID
229
+ days: License validity in days
230
+ max_hwids: Maximum allowed hardware IDs
231
+
232
+ Returns:
233
+ Created license data
234
+ """
235
+ data = {
236
+ 'app_id': app_id,
237
+ 'days': days,
238
+ 'max_hwids': max_hwids
239
+ }
240
+ return await self.client.post('/licenses', data)
241
+
242
+ async def get_licenses(self, app_id: str) -> List[Dict[str, Any]]:
243
+ """
244
+ Get all licenses for application
245
+
246
+ Args:
247
+ app_id: Application ID
248
+
249
+ Returns:
250
+ List of licenses
251
+ """
252
+ result = await self.client.get(f'/licenses/{app_id}')
253
+ return result.get('licenses', [])
254
+
255
+ async def get_license_details(self, license_key: str) -> Dict[str, Any]:
256
+ """
257
+ Get license details
258
+
259
+ Args:
260
+ license_key: License key
261
+
262
+ Returns:
263
+ License details
264
+ """
265
+ return await self.client.get(f'/licenses/{license_key}')
266
+
267
+ async def delete_unused(self, app_id: str) -> Dict[str, Any]:
268
+ """
269
+ Delete unused licenses
270
+
271
+ Args:
272
+ app_id: Application ID
273
+
274
+ Returns:
275
+ Deletion result
276
+ """
277
+ return await self.client.delete(f'/licenses/{app_id}/unused')
278
+
279
+ async def revoke_license(self, license_key: str) -> Dict[str, Any]:
280
+ """
281
+ Revoke license
282
+
283
+ Args:
284
+ license_key: License key to revoke
285
+
286
+ Returns:
287
+ Revocation result
288
+ """
289
+ return await self.client.delete(f'/licenses/{license_key}')
290
+
291
+
292
+ class UsersHandler(BaseHandler):
293
+ """Handler for user management endpoints"""
294
+
295
+ async def get_users(self, app_id: str) -> List[Dict[str, Any]]:
296
+ """
297
+ Get all users for application
298
+
299
+ Args:
300
+ app_id: Application ID
301
+
302
+ Returns:
303
+ List of users
304
+ """
305
+ result = await self.client.get(f'/users/{app_id}')
306
+ return result.get('users', [])
307
+
308
+ async def get_user_details(self, app_id: str, username: str) -> Dict[str, Any]:
309
+ """
310
+ Get user details
311
+
312
+ Args:
313
+ app_id: Application ID
314
+ username: Username
315
+
316
+ Returns:
317
+ User details
318
+ """
319
+ return await self.client.get(f'/users/{app_id}/{username}')
320
+
321
+ async def disable_user(self, app_id: str, username: str) -> Dict[str, Any]:
322
+ """
323
+ Disable user
324
+
325
+ Args:
326
+ app_id: Application ID
327
+ username: Username to disable
328
+
329
+ Returns:
330
+ Disable result
331
+ """
332
+ return await self.client.post(f'/users/{app_id}/{username}/disable')
333
+
334
+ async def enable_user(self, app_id: str, username: str) -> Dict[str, Any]:
335
+ """
336
+ Enable user
337
+
338
+ Args:
339
+ app_id: Application ID
340
+ username: Username to enable
341
+
342
+ Returns:
343
+ Enable result
344
+ """
345
+ return await self.client.post(f'/users/{app_id}/{username}/enable')
346
+
347
+ async def delete_user(self, app_id: str, username: str) -> Dict[str, Any]:
348
+ """
349
+ Delete user
350
+
351
+ Args:
352
+ app_id: Application ID
353
+ username: Username to delete
354
+
355
+ Returns:
356
+ Deletion result
357
+ """
358
+ return await self.client.delete(f'/users/{app_id}/{username}')
359
+
360
+ async def update_user_password(self, app_id: str, username: str, new_password: str) -> Dict[str, Any]:
361
+ """
362
+ Update user password
363
+
364
+ Args:
365
+ app_id: Application ID
366
+ username: Username
367
+ new_password: New password
368
+
369
+ Returns:
370
+ Update result
371
+ """
372
+ data = {'new_password': new_password}
373
+ return await self.client.put(f'/users/{app_id}/{username}/password', data)
374
+
375
+
376
+ class SecurityHandler(BaseHandler):
377
+ """Handler for security management endpoints"""
378
+
379
+ async def ban_hwid(self, app_id: str, hwid: str) -> Dict[str, Any]:
380
+ """
381
+ Ban hardware ID
382
+
383
+ Args:
384
+ app_id: Application ID
385
+ hwid: Hardware ID to ban
386
+
387
+ Returns:
388
+ Ban result
389
+ """
390
+ data = {'hwid': hwid}
391
+ return await self.client.post(f'/security/{app_id}/ban-hwid', data)
392
+
393
+ async def unban_hwid(self, app_id: str, hwid: str) -> Dict[str, Any]:
394
+ """
395
+ Unban hardware ID
396
+
397
+ Args:
398
+ app_id: Application ID
399
+ hwid: Hardware ID to unban
400
+
401
+ Returns:
402
+ Unban result
403
+ """
404
+ data = {'hwid': hwid}
405
+ return await self.client.post(f'/security/{app_id}/unban-hwid', data)
406
+
407
+ async def ban_ip(self, app_id: str, ip_address: str) -> Dict[str, Any]:
408
+ """
409
+ Ban IP address
410
+
411
+ Args:
412
+ app_id: Application ID
413
+ ip_address: IP address to ban
414
+
415
+ Returns:
416
+ Ban result
417
+ """
418
+ data = {'ip_address': ip_address}
419
+ return await self.client.post(f'/security/{app_id}/ban-ip', data)
420
+
421
+ async def unban_ip(self, app_id: str, ip_address: str) -> Dict[str, Any]:
422
+ """
423
+ Unban IP address
424
+
425
+ Args:
426
+ app_id: Application ID
427
+ ip_address: IP address to unban
428
+
429
+ Returns:
430
+ Unban result
431
+ """
432
+ data = {'ip_address': ip_address}
433
+ return await self.client.post(f'/security/{app_id}/unban-ip', data)
434
+
435
+ async def get_banned_hwids(self, app_id: str) -> List[Dict[str, Any]]:
436
+ """
437
+ Get banned hardware IDs
438
+
439
+ Args:
440
+ app_id: Application ID
441
+
442
+ Returns:
443
+ List of banned hardware IDs
444
+ """
445
+ result = await self.client.get(f'/security/{app_id}/banned-hwids')
446
+ return result.get('hwids', [])
447
+
448
+ async def get_banned_ips(self, app_id: str) -> List[Dict[str, Any]]:
449
+ """
450
+ Get banned IP addresses
451
+
452
+ Args:
453
+ app_id: Application ID
454
+
455
+ Returns:
456
+ List of banned IP addresses
457
+ """
458
+ result = await self.client.get(f'/security/{app_id}/banned-ips')
459
+ return result.get('ips', [])
460
+
461
+
462
+ class WebhooksHandler(BaseHandler):
463
+ """Handler for webhook management endpoints"""
464
+
465
+ async def create_webhook(self,
466
+ app_id: str,
467
+ url: str,
468
+ events: List[str],
469
+ secret: str = None) -> Dict[str, Any]:
470
+ """
471
+ Create webhook
472
+
473
+ Args:
474
+ app_id: Application ID
475
+ url: Webhook URL
476
+ events: List of events to subscribe to
477
+ secret: Webhook secret for signature verification
478
+
479
+ Returns:
480
+ Created webhook data
481
+ """
482
+ data = {
483
+ 'url': url,
484
+ 'events': events
485
+ }
486
+ if secret:
487
+ data['secret'] = secret
488
+
489
+ return await self.client.post(f'/webhooks/{app_id}', data)
490
+
491
+ async def list_webhooks(self, app_id: str) -> List[Dict[str, Any]]:
492
+ """
493
+ List webhooks for application
494
+
495
+ Args:
496
+ app_id: Application ID
497
+
498
+ Returns:
499
+ List of webhooks
500
+ """
501
+ result = await self.client.get(f'/webhooks/{app_id}')
502
+ return result.get('webhooks', [])
503
+
504
+ async def get_webhook_details(self, app_id: str, webhook_id: str) -> Dict[str, Any]:
505
+ """
506
+ Get webhook details
507
+
508
+ Args:
509
+ app_id: Application ID
510
+ webhook_id: Webhook ID
511
+
512
+ Returns:
513
+ Webhook details
514
+ """
515
+ return await self.client.get(f'/webhooks/{app_id}/{webhook_id}')
516
+
517
+ async def update_webhook(self,
518
+ app_id: str,
519
+ webhook_id: str,
520
+ url: str = None,
521
+ events: List[str] = None,
522
+ secret: str = None) -> Dict[str, Any]:
523
+ """
524
+ Update webhook
525
+
526
+ Args:
527
+ app_id: Application ID
528
+ webhook_id: Webhook ID
529
+ url: New webhook URL
530
+ events: New list of events
531
+ secret: New webhook secret
532
+
533
+ Returns:
534
+ Updated webhook data
535
+ """
536
+ data = {}
537
+ if url:
538
+ data['url'] = url
539
+ if events:
540
+ data['events'] = events
541
+ if secret:
542
+ data['secret'] = secret
543
+
544
+ return await self.client.put(f'/webhooks/{app_id}/{webhook_id}', data)
545
+
546
+ async def delete_webhook(self, app_id: str, webhook_id: str) -> Dict[str, Any]:
547
+ """
548
+ Delete webhook
549
+
550
+ Args:
551
+ app_id: Application ID
552
+ webhook_id: Webhook ID
553
+
554
+ Returns:
555
+ Deletion result
556
+ """
557
+ return await self.client.delete(f'/webhooks/{app_id}/{webhook_id}')
558
+
559
+ async def test_webhook(self, app_id: str, webhook_id: str) -> Dict[str, Any]:
560
+ """
561
+ Test webhook with sample data
562
+
563
+ Args:
564
+ app_id: Application ID
565
+ webhook_id: Webhook ID
566
+
567
+ Returns:
568
+ Test result
569
+ """
570
+ return await self.client.post(f'/webhooks/{app_id}/{webhook_id}/test')