django-clerk-users 0.0.1__py3-none-any.whl → 0.0.2__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.
Files changed (44) hide show
  1. django_clerk_users/__init__.py +78 -7
  2. django_clerk_users/apps.py +20 -0
  3. django_clerk_users/authentication/__init__.py +24 -0
  4. django_clerk_users/authentication/backends.py +89 -0
  5. django_clerk_users/authentication/drf.py +111 -0
  6. django_clerk_users/authentication/utils.py +171 -0
  7. django_clerk_users/caching.py +161 -0
  8. django_clerk_users/checks.py +127 -0
  9. django_clerk_users/client.py +32 -0
  10. django_clerk_users/decorators.py +181 -0
  11. django_clerk_users/exceptions.py +51 -0
  12. django_clerk_users/management/__init__.py +0 -0
  13. django_clerk_users/management/commands/__init__.py +0 -0
  14. django_clerk_users/management/commands/migrate_users_to_clerk.py +223 -0
  15. django_clerk_users/management/commands/sync_clerk_organizations.py +191 -0
  16. django_clerk_users/management/commands/sync_clerk_users.py +114 -0
  17. django_clerk_users/managers.py +121 -0
  18. django_clerk_users/middleware/__init__.py +9 -0
  19. django_clerk_users/middleware/auth.py +201 -0
  20. django_clerk_users/migrations/0001_initial.py +174 -0
  21. django_clerk_users/migrations/__init__.py +0 -0
  22. django_clerk_users/models.py +174 -0
  23. django_clerk_users/organizations/__init__.py +8 -0
  24. django_clerk_users/organizations/admin.py +81 -0
  25. django_clerk_users/organizations/apps.py +8 -0
  26. django_clerk_users/organizations/middleware.py +130 -0
  27. django_clerk_users/organizations/models.py +316 -0
  28. django_clerk_users/organizations/webhooks.py +417 -0
  29. django_clerk_users/settings.py +37 -0
  30. django_clerk_users/testing.py +381 -0
  31. django_clerk_users/utils.py +210 -0
  32. django_clerk_users/webhooks/__init__.py +26 -0
  33. django_clerk_users/webhooks/handlers.py +346 -0
  34. django_clerk_users/webhooks/security.py +108 -0
  35. django_clerk_users/webhooks/signals.py +42 -0
  36. django_clerk_users/webhooks/views.py +76 -0
  37. django_clerk_users-0.0.2.dist-info/METADATA +228 -0
  38. django_clerk_users-0.0.2.dist-info/RECORD +41 -0
  39. django_clerk_users/main.py +0 -2
  40. django_clerk_users-0.0.1.dist-info/METADATA +0 -24
  41. django_clerk_users-0.0.1.dist-info/RECORD +0 -7
  42. {django_clerk_users-0.0.1.dist-info → django_clerk_users-0.0.2.dist-info}/WHEEL +0 -0
  43. {django_clerk_users-0.0.1.dist-info → django_clerk_users-0.0.2.dist-info}/licenses/LICENSE +0 -0
  44. {django_clerk_users-0.0.1.dist-info → django_clerk_users-0.0.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-clerk-users
3
+ Version: 0.0.2
4
+ Summary: Integrate Clerk with Django
5
+ Project-URL: Changelog, https://github.com/jmitchel3/django-clerk-users
6
+ Project-URL: Documentation, https://github.com/jmitchel3/django-clerk-users
7
+ Project-URL: Funding, https://github.com/jmitchel3/django-clerk-users
8
+ Project-URL: Repository, https://github.com/jmitchel3/django-clerk-users
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Framework :: Django
11
+ Classifier: Framework :: Django :: 4.2
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Requires-Python: >=3.12
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: django>=4.2
20
+ Requires-Dist: clerk-backend-api>=1.0.0
21
+ Requires-Dist: svix>=1.0.0
22
+ Provides-Extra: drf
23
+ Requires-Dist: djangorestframework>=3.14; extra == "drf"
24
+ Dynamic: license-file
25
+
26
+ # Django Clerk Users
27
+
28
+ Integrate [Clerk](https://clerk.com) authentication with Django.
29
+
30
+ > **Note:** This package is in early development (v0.0.2). APIs may change.
31
+
32
+ ## Features
33
+
34
+ - Custom user model (`ClerkUser`) with Clerk integration
35
+ - JWT token validation via Clerk SDK
36
+ - Session-based authentication middleware (validates once, caches in session)
37
+ - Webhook handling with Svix signature verification
38
+ - Optional organizations support (separate sub-app)
39
+ - Django REST Framework authentication (optional)
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ pip install django-clerk-users
45
+ ```
46
+
47
+ For Django REST Framework support:
48
+
49
+ ```bash
50
+ pip install django-clerk-users[drf]
51
+ ```
52
+
53
+ ## Quick Start
54
+
55
+ ### 1. Add to installed apps
56
+
57
+ ```python
58
+ INSTALLED_APPS = [
59
+ # ...
60
+ "django_clerk_users",
61
+ # Optional: for organization support
62
+ # "django_clerk_users.organizations",
63
+ ]
64
+ ```
65
+
66
+ ### 2. Configure settings
67
+
68
+ ```python
69
+ # Required
70
+ CLERK_SECRET_KEY = "sk_live_..." # From Clerk Dashboard
71
+ CLERK_WEBHOOK_SIGNING_KEY = "whsec_..." # From Clerk Webhooks
72
+ CLERK_FRONTEND_HOSTS = ["https://your-app.com"] # Your frontend URLs
73
+
74
+ # Optional
75
+ CLERK_SESSION_REVALIDATION_SECONDS = 300 # Re-validate JWT every 5 minutes
76
+ CLERK_CACHE_TIMEOUT = 300 # Cache timeout for user lookups
77
+ ```
78
+
79
+ ### 3. Set the user model
80
+
81
+ ```python
82
+ AUTH_USER_MODEL = "django_clerk_users.ClerkUser"
83
+ ```
84
+
85
+ Or extend the abstract model for custom fields:
86
+
87
+ ```python
88
+ # myapp/models.py
89
+ from django_clerk_users.models import AbstractClerkUser
90
+
91
+ class CustomUser(AbstractClerkUser):
92
+ company = models.CharField(max_length=255, blank=True)
93
+
94
+ class Meta(AbstractClerkUser.Meta):
95
+ swappable = "AUTH_USER_MODEL"
96
+
97
+ # settings.py
98
+ AUTH_USER_MODEL = "myapp.CustomUser"
99
+ ```
100
+
101
+ ### 4. Add middleware
102
+
103
+ ```python
104
+ MIDDLEWARE = [
105
+ "django.middleware.security.SecurityMiddleware",
106
+ "django.contrib.sessions.middleware.SessionMiddleware",
107
+ "django.middleware.common.CommonMiddleware",
108
+ "django.middleware.csrf.CsrfViewMiddleware",
109
+ "django.contrib.auth.middleware.AuthenticationMiddleware",
110
+ "django_clerk_users.middleware.ClerkAuthMiddleware", # Add after AuthenticationMiddleware
111
+ # ...
112
+ ]
113
+ ```
114
+
115
+ ### 5. Add authentication backend
116
+
117
+ ```python
118
+ AUTHENTICATION_BACKENDS = [
119
+ "django_clerk_users.authentication.ClerkBackend",
120
+ ]
121
+ ```
122
+
123
+ ### 6. Run migrations
124
+
125
+ ```bash
126
+ python manage.py migrate
127
+ ```
128
+
129
+ ### 7. Configure webhooks
130
+
131
+ Add the webhook URL to your `urls.py`:
132
+
133
+ ```python
134
+ from django_clerk_users.webhooks import clerk_webhook_view
135
+
136
+ urlpatterns = [
137
+ # ...
138
+ path("webhooks/clerk/", clerk_webhook_view, name="clerk_webhook"),
139
+ ]
140
+ ```
141
+
142
+ Then configure your Clerk Dashboard to send webhooks to `https://your-app.com/webhooks/clerk/`.
143
+
144
+ ## Usage
145
+
146
+ ### Accessing the user in views
147
+
148
+ ```python
149
+ def my_view(request):
150
+ if request.user.is_authenticated:
151
+ # Access Clerk user attributes
152
+ print(request.user.clerk_id)
153
+ print(request.user.email)
154
+ print(request.user.full_name)
155
+
156
+ # Access organization (if using organizations)
157
+ print(request.org) # Organization ID from JWT
158
+ ```
159
+
160
+ ### Decorators
161
+
162
+ ```python
163
+ from django_clerk_users.decorators import clerk_user_required
164
+
165
+ @clerk_user_required
166
+ def protected_view(request):
167
+ # Only authenticated Clerk users can access
168
+ return HttpResponse(f"Hello, {request.user.email}")
169
+ ```
170
+
171
+ ### Django REST Framework
172
+
173
+ ```python
174
+ # settings.py
175
+ REST_FRAMEWORK = {
176
+ "DEFAULT_AUTHENTICATION_CLASSES": [
177
+ "django_clerk_users.authentication.ClerkAuthentication",
178
+ ],
179
+ }
180
+ ```
181
+
182
+ ## Organizations (Optional)
183
+
184
+ For Clerk organization support:
185
+
186
+ ```python
187
+ # settings.py
188
+ INSTALLED_APPS = [
189
+ # ...
190
+ "django_clerk_users",
191
+ "django_clerk_users.organizations",
192
+ ]
193
+
194
+ MIDDLEWARE = [
195
+ # ...
196
+ "django_clerk_users.middleware.ClerkAuthMiddleware",
197
+ "django_clerk_users.organizations.middleware.ClerkOrganizationMiddleware",
198
+ ]
199
+ ```
200
+
201
+ ## Management Commands
202
+
203
+ ```bash
204
+ # Sync users from Clerk
205
+ python manage.py sync_clerk_users
206
+
207
+ # Sync organizations from Clerk
208
+ python manage.py sync_clerk_organizations
209
+ ```
210
+
211
+ ## Configuration Reference
212
+
213
+ | Setting | Required | Default | Description |
214
+ |---------|----------|---------|-------------|
215
+ | `CLERK_SECRET_KEY` | Yes | - | Your Clerk secret key |
216
+ | `CLERK_WEBHOOK_SIGNING_KEY` | Yes* | - | Webhook signing secret (*required for webhooks) |
217
+ | `CLERK_FRONTEND_HOSTS` | Yes | `[]` | Authorized frontend URLs |
218
+ | `CLERK_SESSION_REVALIDATION_SECONDS` | No | `300` | JWT revalidation interval |
219
+ | `CLERK_CACHE_TIMEOUT` | No | `300` | User cache timeout |
220
+ | `CLERK_ORG_CACHE_TIMEOUT` | No | `900` | Organization cache timeout |
221
+
222
+ ## License
223
+
224
+ MIT
225
+
226
+ ## Contributing
227
+
228
+ Contributions are welcome! Please open an issue or PR on [GitHub](https://github.com/jmitchel3/django-clerk-users).
@@ -0,0 +1,41 @@
1
+ django_clerk_users/__init__.py,sha256=Ph93iT6_RNdZej3GM6cez-cJjiXw6w1V-u4GCnGP8TY,2287
2
+ django_clerk_users/apps.py,sha256=upj0qWYVg4P2D6_Vt8QZWTfBpAdIP7EAQjVjEnfHLRA,729
3
+ django_clerk_users/caching.py,sha256=QXRd9cFvvUucrnLBd7_PId3xDodqcessDMybkHyskkU,4651
4
+ django_clerk_users/checks.py,sha256=gnHccAyXixtGToGhgWl4gfCY-qPB5ckimpDVadOP3E4,4191
5
+ django_clerk_users/client.py,sha256=-nBXsPOibVwD7zXQ-Z-qTBb7NyPuUZpvlDcAlDVFUBA,815
6
+ django_clerk_users/decorators.py,sha256=Hm86XIxNdSiuDmqT8tFRrz6sQR9IOxB7zfxfO8MeJLg,5011
7
+ django_clerk_users/exceptions.py,sha256=nVTJR1d5PxuMqC8js1Sj-MRHJHkI4KUwphjuCEN4fiM,890
8
+ django_clerk_users/managers.py,sha256=PH1sk0LB9Fj8qrYG5jzpBKqWUbmaSZ3zaXEbx4eNjdY,3581
9
+ django_clerk_users/models.py,sha256=cCSgKoBivdijfLeiOoxwpber2tqNSCua5pBcQ7BbXQQ,4873
10
+ django_clerk_users/settings.py,sha256=pRyt_kSPWOT8CkTvyce3sf0RxfIoG5DEwnGUT8bIDi8,1305
11
+ django_clerk_users/testing.py,sha256=ZoYi7dG_HjSp19_c1AvILOoCfHlofs7LN-5ALS_UhDw,12160
12
+ django_clerk_users/utils.py,sha256=bQWfPUKfVvXi69Ctny1T1Kxzk-qMDpXQBRVa6URH53I,5886
13
+ django_clerk_users/authentication/__init__.py,sha256=PStQVzC-CA2Guyo4ksrxP58o93mfygW4qcJXWEjs6ak,614
14
+ django_clerk_users/authentication/backends.py,sha256=We0P2AhMv_DB_ZwtFGmmjWKvT5Cewy441Iua2lAZZCg,2400
15
+ django_clerk_users/authentication/drf.py,sha256=AqHvZTe9RnxN7FVzlSUXR72QBj2imGglkx9rpOrRDIk,3215
16
+ django_clerk_users/authentication/utils.py,sha256=tpnRXQLbQPkosKV8OhxtXpapuema4c08g58YYmMl3js,5326
17
+ django_clerk_users/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
+ django_clerk_users/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ django_clerk_users/management/commands/migrate_users_to_clerk.py,sha256=qjw4Q6pU7-4Tt7XourTzCw7IBm5kkOau4mPkW2Vz13E,8047
20
+ django_clerk_users/management/commands/sync_clerk_organizations.py,sha256=G1kasAPvvwM-PPb5xXxKNlex_-gWyKDP2HLS5g8hVkk,6656
21
+ django_clerk_users/management/commands/sync_clerk_users.py,sha256=hvWrvcqAkZHvjqQAOj3-e6pKx5TKtArmlsHDUottRMM,3755
22
+ django_clerk_users/middleware/__init__.py,sha256=tnr4eBer0KGVBAZBgBQZVpcL7jf8t2_CBLsMnau5JW4,153
23
+ django_clerk_users/middleware/auth.py,sha256=LTUE_gFXlBRNg9kk2mHmHNKz3gpWKgCs66xyKE1_k1c,7435
24
+ django_clerk_users/migrations/0001_initial.py,sha256=tnPvGlLnWrItuhYS0s5mr3TJ8__2e_yNKJS4nsFuWhk,6246
25
+ django_clerk_users/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
+ django_clerk_users/organizations/__init__.py,sha256=NZU2C8F4Trm63_qaUf78jROKz6XFnu36uREkw7g_yho,270
27
+ django_clerk_users/organizations/admin.py,sha256=u7qHMgb11akHiJ2FCzqbSLQ3_TsTiejf0wH10f5_PPQ,1838
28
+ django_clerk_users/organizations/apps.py,sha256=IgKNl5REkAgLDHC06GFI-a3x3Mi2HWN4L-El0Ef6CE8,252
29
+ django_clerk_users/organizations/middleware.py,sha256=5Gvu28SCEqpuIjr2Fah5O85m0wnjMiDp4vxdvVzJh68,4129
30
+ django_clerk_users/organizations/models.py,sha256=2YWLHuWCo2Q3pEq_Gx5SadUGqSmi8MZhEDdfeVn1URo,8673
31
+ django_clerk_users/organizations/webhooks.py,sha256=zp16_vL5j7DEaVC5ZxgYwrE8zPpUsRIq8TGBd8SYhoo,14321
32
+ django_clerk_users/webhooks/__init__.py,sha256=XlpsPmc_lHQkZVMeuXce_2hsq7WZzXOXNy36kiQA5Lk,558
33
+ django_clerk_users/webhooks/handlers.py,sha256=GnotJNhN809DsrbfZjtJD0KurThKyAXZS982a41ljwg,9457
34
+ django_clerk_users/webhooks/security.py,sha256=Ig2ZxF8SxX5o-4bNRehFhip4hVvcQxoGsTj3sTY3WSU,3461
35
+ django_clerk_users/webhooks/signals.py,sha256=bytshg7IMDnlvnCZ0_TGjUXZZLRNxtn2RSx97qacZ-w,1668
36
+ django_clerk_users/webhooks/views.py,sha256=0-ilzzO7tBfc-pENMy0ZSSkQ4uPqH2QAt249EK2wQKA,2287
37
+ django_clerk_users-0.0.2.dist-info/licenses/LICENSE,sha256=X4PZDRQG4RmPhHU5c0G21Ki9LXWDCuLQ8W4mnED5RDU,1071
38
+ django_clerk_users-0.0.2.dist-info/METADATA,sha256=pQfVSZMxsGZH7UB9mBkus-SKoictxbzp9fvkXHh9Jiw,5700
39
+ django_clerk_users-0.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
40
+ django_clerk_users-0.0.2.dist-info/top_level.txt,sha256=m2CUZNVRrrVHorKdGlRLuGJbc0NFgx1f2GGjpTLuGXY,19
41
+ django_clerk_users-0.0.2.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- def hello_world():
2
- return "Hello from django-clerk-users!"
@@ -1,24 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: django-clerk-users
3
- Version: 0.0.1
4
- Summary: Integrate Clerk with Django
5
- Project-URL: Changelog, https://github.com/jmitchel3/django-clerk-users
6
- Project-URL: Documentation, https://github.com/jmitchel3/django-clerk-users
7
- Project-URL: Funding, https://github.com/jmitchel3/django-clerk-users
8
- Project-URL: Repository, https://github.com/jmitchel3/django-clerk-users
9
- Classifier: Development Status :: 4 - Beta
10
- Classifier: Framework :: Django
11
- Classifier: Framework :: Django :: 4.2
12
- Classifier: Programming Language :: Python :: 3 :: Only
13
- Classifier: Programming Language :: Python :: 3.12
14
- Classifier: Programming Language :: Python :: 3.13
15
- Classifier: Programming Language :: Python :: 3.14
16
- Requires-Python: >=3.12
17
- Description-Content-Type: text/markdown
18
- License-File: LICENSE
19
- Requires-Dist: django>=4.2
20
- Dynamic: license-file
21
-
22
- # Django Clerk Users
23
-
24
- Integrate Clerk with Django, coming soon.
@@ -1,7 +0,0 @@
1
- django_clerk_users/__init__.py,sha256=L_pMt2_tM2dlDpsSo12M-kG_qW6TlMCr-sk0KMfKAxE,549
2
- django_clerk_users/main.py,sha256=RfM09MvG3C2hmAH5l0RM-lbYatU_58RmkEpjrHtE2BM,63
3
- django_clerk_users-0.0.1.dist-info/licenses/LICENSE,sha256=X4PZDRQG4RmPhHU5c0G21Ki9LXWDCuLQ8W4mnED5RDU,1071
4
- django_clerk_users-0.0.1.dist-info/METADATA,sha256=S8sFVa0UAXvgXnLdmBLrD7QXzR7Tubn76v7cnqyrn3c,913
5
- django_clerk_users-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- django_clerk_users-0.0.1.dist-info/top_level.txt,sha256=m2CUZNVRrrVHorKdGlRLuGJbc0NFgx1f2GGjpTLuGXY,19
7
- django_clerk_users-0.0.1.dist-info/RECORD,,