Skip to content

Commit 0032f47

Browse files
authored
Merge pull request #4 from workos-inc/feature/webhooks-validation-route
Add webhooks validation route and update dependency versions
2 parents bbf4c5f + b33ad99 commit 0032f47

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

python-django-directory-sync-example/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ If you get stuck, please reach out to us at [email protected] so we can help.
3131
$ git clone [email protected]:workos-inc/python-django-example-applications.git
3232
```
3333

34-
3. Navigate to the Admin Portal example app within the cloned repo.
34+
3. Navigate to the Directory Sync example app within the cloned repo.
3535
```bash
3636
$ cd python-django-example-applications/python-django-directory-sync-example
3737
````
@@ -67,6 +67,7 @@ If you get stuck, please reach out to us at [email protected] so we can help.
6767
```bash
6868
export WORKOS_API_KEY=<value found in step 6>
6969
export DIRECTORY_ID=<value found in step 6>
70+
export WEBHOOKS_SECRET=<value found in WorkOS Dashboard>
7071
```
7172

7273
To exit the Nano text editor, type `CTRL + x`. When prompted to "Save modified buffer", type `Y`, then press the `Enter` or `Return` key.

python-django-directory-sync-example/directory_sync/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
path('', views.get_home, name='home'),
66
path('users', views.get_directory_users, name='users'),
77
path('groups', views.get_directory_groups, name='groups'),
8+
path('webhooks', views.webhooks, name='webhooks'),
89
]

python-django-directory-sync-example/directory_sync/views.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
2+
import json
3+
from django.http.response import HttpResponse
24
import workos
35
from django.conf import settings
46
from django.shortcuts import render
5-
7+
from django.views.decorators.csrf import csrf_exempt
68

79
workos.api_key = os.getenv('WORKOS_API_KEY')
810
workos.base_api_url = 'http://localhost:8000/' if settings.DEBUG else workos.base_api_url
@@ -20,3 +22,19 @@ def get_directory_users(request):
2022
def get_directory_groups(request):
2123
groups = workos.client.directory_sync.list_groups(directory=directory_id)
2224
return render(request, 'directory_sync/groups.html', {"groups": groups})
25+
26+
@csrf_exempt
27+
def webhooks(request):
28+
dict_payload = json.loads(request.body)
29+
payload = json.dumps(dict_payload)
30+
sig_header = request.headers.get('WorkOS-Signature')
31+
32+
response = workos.client.webhooks.verify_event(
33+
payload = payload,
34+
sig_header = sig_header,
35+
secret = os.getenv('WEBHOOKS_SECRET')
36+
)
37+
38+
print(response)
39+
40+
return HttpResponse(200)
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
asgiref==3.3.1
22
certifi==2020.12.5
33
chardet==4.0.0
4-
Django==3.1.7
4+
Django==3.1.13
55
idna==2.10
66
pytz==2021.1
77
requests==2.25.1
8-
sqlparse==0.4.1
9-
urllib3==1.26.4
10-
workos==0.8.6
8+
sqlparse==0.4.2
9+
urllib3==1.26.5
10+
workos==1.5.1
11+
python-dotenv

python-django-directory-sync-example/workos_django/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
SECRET_KEY = 'of3^3#x@z=(qe!s_stg-a5k1ojxl+ix(^09ewv+$9vt1-u$1d#'
2424

2525
# SECURITY WARNING: don't run with debug turned on in production!
26-
DEBUG = False
26+
DEBUG = True
2727

28-
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
28+
ALLOWED_HOSTS = ['*']
2929

3030

3131
# Application definition

0 commit comments

Comments
 (0)