auth-drf 0.1.1__tar.gz

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 (34) hide show
  1. auth_drf-0.1.1/LICENSE.txt +22 -0
  2. auth_drf-0.1.1/PKG-INFO +480 -0
  3. auth_drf-0.1.1/README.md +467 -0
  4. auth_drf-0.1.1/pyproject.toml +26 -0
  5. auth_drf-0.1.1/setup.cfg +4 -0
  6. auth_drf-0.1.1/src/auth_drf/__init__.py +0 -0
  7. auth_drf-0.1.1/src/auth_drf/admin.py +3 -0
  8. auth_drf-0.1.1/src/auth_drf/apps.py +5 -0
  9. auth_drf-0.1.1/src/auth_drf/migrations/__init__.py +0 -0
  10. auth_drf-0.1.1/src/auth_drf/models/__init__.py +8 -0
  11. auth_drf-0.1.1/src/auth_drf/models/role_mixin_model.py +50 -0
  12. auth_drf-0.1.1/src/auth_drf/models/role_model.py +24 -0
  13. auth_drf-0.1.1/src/auth_drf/models/token_model.py +67 -0
  14. auth_drf-0.1.1/src/auth_drf/models/user_model.py +67 -0
  15. auth_drf-0.1.1/src/auth_drf/serializers/__init__.py +2 -0
  16. auth_drf-0.1.1/src/auth_drf/serializers/auth_serializer.py +67 -0
  17. auth_drf-0.1.1/src/auth_drf/serializers/permission_serializer.py +10 -0
  18. auth_drf-0.1.1/src/auth_drf/serializers/role_serializer.py +109 -0
  19. auth_drf-0.1.1/src/auth_drf/services/__init__.py +14 -0
  20. auth_drf-0.1.1/src/auth_drf/services/auth_service.py +69 -0
  21. auth_drf-0.1.1/src/auth_drf/services/jwt_service.py +37 -0
  22. auth_drf-0.1.1/src/auth_drf/services/permissions_service.py +33 -0
  23. auth_drf-0.1.1/src/auth_drf/services/role_service.py +79 -0
  24. auth_drf-0.1.1/src/auth_drf/services/token_service.py +117 -0
  25. auth_drf-0.1.1/src/auth_drf/tests.py +3 -0
  26. auth_drf-0.1.1/src/auth_drf/urls.py +14 -0
  27. auth_drf-0.1.1/src/auth_drf/views/__init__.py +8 -0
  28. auth_drf-0.1.1/src/auth_drf/views/auth_view.py +89 -0
  29. auth_drf-0.1.1/src/auth_drf/views/role_view.py +101 -0
  30. auth_drf-0.1.1/src/auth_drf.egg-info/PKG-INFO +480 -0
  31. auth_drf-0.1.1/src/auth_drf.egg-info/SOURCES.txt +32 -0
  32. auth_drf-0.1.1/src/auth_drf.egg-info/dependency_links.txt +1 -0
  33. auth_drf-0.1.1/src/auth_drf.egg-info/requires.txt +2 -0
  34. auth_drf-0.1.1/src/auth_drf.egg-info/top_level.txt +1 -0
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sahil Sheoran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,480 @@
1
+ Metadata-Version: 2.4
2
+ Name: auth-drf
3
+ Version: 0.1.1
4
+ Summary: Authentication package for Django REST Framework
5
+ Author-email: Sahil <sahilsheoran24@gmail.com>
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE.txt
10
+ Requires-Dist: djangorestframework>=3.17.1
11
+ Requires-Dist: djangorestframework-simplejwt>=5.5.1
12
+ Dynamic: license-file
13
+
14
+ # auth-drf
15
+
16
+ A Django REST Framework package that provides JWT Authentication and Role-Based Access Control (RBAC).
17
+
18
+ ---
19
+
20
+ # Features
21
+
22
+ * JWT Authentication
23
+ * User Registration
24
+ * User Login
25
+ * User Logout
26
+ * Refresh Token Rotation
27
+ * Role-Based Access Control (RBAC)
28
+ * Role CRUD APIs
29
+ * Django Permission Integration
30
+
31
+ ---
32
+
33
+ # Requirements
34
+
35
+ * Python 3.12+
36
+ * Django 5.x / 6.x
37
+ * Django REST Framework
38
+ * djangorestframework-simplejwt
39
+
40
+ ---
41
+
42
+ # Installation
43
+
44
+ ## Install from PyPI
45
+
46
+ ```bash
47
+ pip install auth-drf
48
+ ```
49
+
50
+
51
+ ---
52
+
53
+ # Project Setup
54
+
55
+ ## Step 1: Add the package to `INSTALLED_APPS`
56
+
57
+ ```python
58
+ INSTALLED_APPS = [
59
+ ...
60
+
61
+ "rest_framework",
62
+ "auth_drf",
63
+ ]
64
+ ```
65
+
66
+ ---
67
+
68
+ ## Step 2: Create a Custom User Model
69
+
70
+ ```python
71
+ from auth_drf.models.user_model import BaseUser
72
+
73
+ class Customer(BaseUser):
74
+ class Meta:
75
+ abstract = False
76
+ ```
77
+
78
+ > **Note**
79
+ >
80
+ > `Customer` is only an example. Your custom user model can have any name.
81
+
82
+ ---
83
+
84
+ ## Step 3: Configure `AUTH_USER_MODEL`
85
+
86
+ ```python
87
+ AUTH_USER_MODEL = "user_test.Customer"
88
+ ```
89
+
90
+ ---
91
+
92
+ ## Step 4: Configure DRF Authentication
93
+
94
+ ```python
95
+ REST_FRAMEWORK = {
96
+ "DEFAULT_AUTHENTICATION_CLASSES": (
97
+ "rest_framework_simplejwt.authentication.JWTAuthentication",
98
+ ),
99
+ }
100
+ ```
101
+
102
+ ---
103
+
104
+ ## Step 5: Include Package URLs
105
+
106
+ ```python
107
+ from django.contrib import admin
108
+ from django.urls import path, include
109
+
110
+ urlpatterns = [
111
+ path("admin/", admin.site.urls),
112
+ path("", include("auth_drf.urls")),
113
+ ]
114
+ ```
115
+
116
+ ---
117
+
118
+ ## Step 6: Run Migrations
119
+
120
+ ```bash
121
+ python manage.py makemigrations
122
+ python manage.py migrate
123
+ ```
124
+
125
+ ---
126
+
127
+ # Authentication
128
+
129
+ After login, use the Access Token for all protected endpoints.
130
+
131
+ ```http
132
+ Authorization: Bearer <access_token>
133
+ ```
134
+
135
+ ---
136
+
137
+ # API Endpoints
138
+
139
+ | Method | Endpoint |
140
+ | ------ | ---------------------- |
141
+ | POST | `/auth/register/` |
142
+ | POST | `/auth/login/` |
143
+ | POST | `/auth/logout/` |
144
+ | POST | `/auth/token_refresh/` |
145
+ | POST | `/roles/` |
146
+ | PATCH | `/roles/<id>/` |
147
+ | GET | `/roles/` |
148
+ | GET | `/roles/<id>/` |
149
+
150
+ ---
151
+
152
+ # Authentication APIs
153
+
154
+ ## Register User
155
+
156
+ ### Endpoint
157
+
158
+ ```http
159
+ POST /auth/register/
160
+ ```
161
+
162
+ ### Request Payload
163
+
164
+ ```json
165
+ {
166
+ "first_name": "Vinnie",
167
+ "last_name": "Sheoran",
168
+ "email": "vinnie@yopmail.com",
169
+ "username": "vinnie",
170
+ "password": "vinnie"
171
+ }
172
+ ```
173
+
174
+ ### Response
175
+
176
+ ```json
177
+ {
178
+ "success": "Registration Successful",
179
+ "detail": {
180
+ "user": "vinnie@yopmail.com"
181
+ }
182
+ }
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Login User
188
+
189
+ ### Endpoint
190
+
191
+ ```http
192
+ POST /auth/login/
193
+ ```
194
+
195
+ ### Request Payload
196
+
197
+ ```json
198
+ {
199
+ "email": "vinnie@yopmail.com",
200
+ "username": "vinnie",
201
+ "password": "vinnie"
202
+ }
203
+ ```
204
+
205
+ ### Response
206
+
207
+ ```json
208
+ {
209
+ "id": 1,
210
+ "email": "vinnie@yopmail.com",
211
+ "username": "vinnie",
212
+ "permissions": [
213
+ {
214
+ "module": "customer",
215
+ "actions": [
216
+ "add_customer",
217
+ "change_customer",
218
+ "delete_customer",
219
+ "view_customer"
220
+ ]
221
+ }
222
+ ],
223
+ "access": "<access_token>",
224
+ "refresh": "<refresh_token>"
225
+ }
226
+ ```
227
+
228
+ ---
229
+
230
+ ## Logout User
231
+
232
+ ### Endpoint
233
+
234
+ ```http
235
+ POST /auth/logout/
236
+ ```
237
+
238
+ ### Request Payload
239
+
240
+ ```json
241
+ {
242
+ "refresh": "<refresh_token>"
243
+ }
244
+ ```
245
+
246
+ ### Response
247
+
248
+ ```json
249
+ {
250
+ "success": "Logout Successful"
251
+ }
252
+ ```
253
+
254
+ ---
255
+
256
+ ## Refresh Token
257
+
258
+ ### Endpoint
259
+
260
+ ```http
261
+ POST /auth/token_refresh/
262
+ ```
263
+
264
+ ### Request Payload
265
+
266
+ ```json
267
+ {
268
+ "refresh": "<refresh_token>"
269
+ }
270
+ ```
271
+
272
+ ### Response
273
+
274
+ ```json
275
+ {
276
+ "access": "<new_access_token>",
277
+ "refresh": "<new_refresh_token>"
278
+ }
279
+ ```
280
+
281
+ ---
282
+
283
+ # Role APIs
284
+
285
+ ## Create Role
286
+
287
+ ### Endpoint
288
+
289
+ ```http
290
+ POST /roles/
291
+ ```
292
+
293
+ ### Authentication
294
+
295
+ Requires a valid Access Token.
296
+
297
+ ### Request Payload
298
+
299
+ ```json
300
+ {
301
+ "name": "Interns",
302
+ "permissions": [
303
+ {
304
+ "module": "customer",
305
+ "actions": [
306
+ "add_customer",
307
+ "change_customer",
308
+ "delete_customer",
309
+ "view_customer"
310
+ ]
311
+ }
312
+ ]
313
+ }
314
+ ```
315
+
316
+ ### Response
317
+
318
+ ```json
319
+ {
320
+ "id": 5,
321
+ "name": "Interns",
322
+ "permissions": [
323
+ {
324
+ "module": "customer",
325
+ "actions": [
326
+ "add_customer",
327
+ "change_customer",
328
+ "delete_customer",
329
+ "view_customer"
330
+ ]
331
+ }
332
+ ]
333
+ }
334
+ ```
335
+
336
+ ---
337
+
338
+ ## Update Role
339
+
340
+ ### Endpoint
341
+
342
+ ```http
343
+ PATCH /roles/<id>/
344
+ ```
345
+
346
+ ### Authentication
347
+
348
+ Requires a valid Access Token.
349
+
350
+ ### Request Payload
351
+
352
+ ```json
353
+ {
354
+ "name": "Manager",
355
+ "permissions": [
356
+ {
357
+ "module": "customer",
358
+ "actions": [
359
+ "add_customer",
360
+ "change_customer",
361
+ "delete_customer",
362
+ "view_customer"
363
+ ]
364
+ }
365
+ ]
366
+ }
367
+ ```
368
+
369
+ ### Response
370
+
371
+ ```json
372
+ {
373
+ "success": "Role is Updated",
374
+ "data": {
375
+ "id": 3,
376
+ "name": "Manager",
377
+ "permissions": [
378
+ {
379
+ "module": "customer",
380
+ "actions": [
381
+ "add_customer",
382
+ "change_customer",
383
+ "delete_customer",
384
+ "view_customer"
385
+ ]
386
+ }
387
+ ]
388
+ }
389
+ }
390
+ ```
391
+
392
+ ---
393
+
394
+ ## List Roles
395
+
396
+ ### Endpoint
397
+
398
+ ```http
399
+ GET /roles/
400
+ ```
401
+
402
+ ### Authentication
403
+
404
+ Requires a valid Access Token.
405
+
406
+ ### Response
407
+
408
+ ```json
409
+ [
410
+ {
411
+ "id": 2,
412
+ "name": "Administrator",
413
+ "permissions": [
414
+ {
415
+ "module": "customer",
416
+ "actions": [
417
+ "add_customer",
418
+ "change_customer",
419
+ "delete_customer",
420
+ "view_customer"
421
+ ]
422
+ }
423
+ ]
424
+ },
425
+ {
426
+ "id": 3,
427
+ "name": "Manager",
428
+ "permissions": [
429
+ {
430
+ "module": "customer",
431
+ "actions": [
432
+ "add_customer",
433
+ "change_customer",
434
+ "delete_customer",
435
+ "view_customer"
436
+ ]
437
+ }
438
+ ]
439
+ }
440
+ ]
441
+ ```
442
+
443
+ ---
444
+
445
+ ## Retrieve Role
446
+
447
+ ### Endpoint
448
+
449
+ ```http
450
+ GET /roles/<id>/
451
+ ```
452
+
453
+ ### Authentication
454
+
455
+ Requires a valid Access Token.
456
+
457
+ ### Response
458
+
459
+ ```json
460
+ {
461
+ "name": "Manager",
462
+ "permissions": [
463
+ {
464
+ "module": "customer",
465
+ "actions": [
466
+ "add_customer",
467
+ "change_customer",
468
+ "delete_customer",
469
+ "view_customer"
470
+ ]
471
+ }
472
+ ]
473
+ }
474
+ ```
475
+
476
+ ---
477
+
478
+ # License
479
+
480
+ This project is licensed under the MIT License.