Skip to content

Commit eaaf490

Browse files
awolfdenAdam Wolfman
andauthored
Update UI/UX to utilize GET directory endpoint (#6)
Co-authored-by: Adam Wolfman <[email protected]>
1 parent b794745 commit eaaf490

File tree

9 files changed

+71
-16
lines changed

9 files changed

+71
-16
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ If you get stuck, please reach out to us at [email protected] so we can help.
5454

5555
6. Obtain and make note of the following values. In the next step, these will be set as environment variables.
5656
- Your [WorkOS API key](https://dashboard.workos.com/api-keys)
57-
- Your `DIRECTORY_ID`, in the format `directory_<random-alphanumeric-string>`, retrievable from the URL in the Directory Sync area of the WorkOS dashboard:
58-
![](directory_id_location.png)
57+
- Your `WEBHOOKS_SECRET`, retrievable from the URL in the WEBHOOKS area of the WorkOS dashboard. This is only required if you are utilizing the webhooks route of this application to receive and validate webhook events.
5958

6059
7. Ensure you're in the root directory for the example app, `python-django-directory-sync-example/`. Create a `.env` file to securely store the environment variables. Open this file with the Nano text editor. (This file is listed in this repo's `.gitignore` file, so your sensitive information will not be checked into version control.)
6160
```bash
@@ -64,11 +63,10 @@ If you get stuck, please reach out to us at [email protected] so we can help.
6463
```
6564

6665
8. Once the Nano text editor opens, you can directly edit the `.env` file by listing the environment variables:
67-
```bash
68-
export WORKOS_API_KEY=<value found in step 6>
69-
export DIRECTORY_ID=<value found in step 6>
70-
export WEBHOOKS_SECRET=<value found in WorkOS Dashboard>
71-
```
66+
```bash
67+
export WORKOS_API_KEY=<value found in step 6>
68+
export WEBHOOKS_SECRET=<value found in step 6>
69+
```
7270

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

@@ -80,7 +78,7 @@ If you get stuck, please reach out to us at [email protected] so we can help.
8078
You can ensure the environment variables were set correctly by running the following commands. The output should match the corresponding values.
8179
```bash
8280
(env) $ echo $WORKOS_API_KEY
83-
(env) $ echo $DIRECTORY_ID
81+
(env) $ echo $WEBHOOKS_SECRET
8482
```
8583

8684
### Run Django Migrations and Start Server
@@ -122,7 +120,7 @@ If you get stuck, please reach out to us at [email protected] so we can help.
122120
Quit the server with CONTROL-C.
123121
```
124122

125-
12. Once the server is running, navigate to http://localhost:8000 to view the home page of the app where you can then select the view for users or groups. Alternatively you could also view these directly using the following url's: http://localhost:8000/users and http://localhost:8000/groups.
123+
12. Once the server is running, navigate to http://localhost:8000 to view the home page of the app where you can then select the view for users or groups.
126124

127125
- The `/users` URL corresponds to the WorkOS API's [List Directory Users endpoint](https://workos.com/docs/reference/directory-sync/user/list)
128126
- The `/groups` URL corresponds to the WorkOS API's [List Directory Groups endpoint](https://workos.com/docs/reference/directory-sync/group/list)

python-django-directory-sync-example/directory_sync/static/css/main.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ div.text_box {
143143
border-radius: 5px;
144144
border: 2px solid #6363f1;
145145
width: 75%;
146+
max-height: 400px;
147+
overflow: scroll;
146148
padding: 10px;
147149
word-wrap: break-word;
148150
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<html>
2+
<head>
3+
<link rel="stylesheet" href="../../static/css/main.css">
4+
</head>
5+
<body class="container_success">
6+
<div class="logged_in_nav">
7+
<div class="flex">
8+
<p>You're logged in, here is your directory object!</p>
9+
</div>
10+
<div>
11+
<img src="../../static/images/workos_logo_new.png" alt="workos logo">
12+
</div>
13+
</div>
14+
<div class='flex'>
15+
<div class="logged_in_div_left">
16+
<div>
17+
<h1>Your app,</h1>
18+
<h2>Enterprise Ready</h2>
19+
</div>
20+
<div>
21+
<a href="https://workos.com/" target="_blank"><button class='button'>WorkOS</button></a>
22+
<a href="https://workos.com/docs" target="_blank"><button class='button'>Documentation</button></a>
23+
<a href="https://workos.com/docs/reference" target="_blank"><button class='button'>API Reference</button></a>
24+
<a href="https://workos.com/blog" target="_blank"><button class='button'>Blog</button></a>
25+
<a href="javascript:history.back()"><button class='button'>Home</button></a>
26+
27+
</div>
28+
</div>
29+
<div class="logged_in_div_right">
30+
<div class="flex_column">
31+
<h2>Raw Directory Object Details</h2>
32+
<div class="text_box">
33+
<p>{{ directory }}</p>
34+
</div>
35+
</div>
36+
<div class="flex">
37+
<a class="button directory_button" href="/users?id={{directory.id}}">Users</a>
38+
<br>
39+
<a class="button directory_button" href="/groups?id={{directory.id}}">Groups</a>
40+
</div>
41+
</div>
42+
</div>
43+
</body>
44+
</html>

python-django-directory-sync-example/directory_sync/templates/directory_sync/groups.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h2>Enterprise Ready</h2>
2323
<a href="https://workos.com/docs" target="_blank"><button class='button'>Documentation</button></a>
2424
<a href="https://workos.com/docs/reference" target="_blank"><button class='button'>API Reference</button></a>
2525
<a href="https://workos.com/blog" target="_blank"><button class='button'>Blog</button></a>
26-
<a href="javascript:history.back()"><button class="button">Home</button></a>
26+
<a href="javascript:history.back()"><button class="button">Back</button></a>
2727
</div>
2828
</div>
2929
<div class="logged_in_div_right">

python-django-directory-sync-example/directory_sync/templates/directory_sync/home.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ <h1>WorkOS</h1>
1414
</div>
1515
</div>
1616

17-
<h2>Python Django Directory Sync Example App</h2>
18-
<a class="button login_button" href="{% url 'users' %}">Users</a>
19-
<a class="button login_button" href="{% url 'groups' %}">Groups</a>
17+
<h2>Python Flask Directory Sync Example App</h2>
18+
{% for i in directories %}
19+
<a class="button login_button" href="/directory?id={{i.id}}">{{ i.name }}</a>
20+
{% endfor %}
2021
</div>
2122
</body>
2223
</html>

python-django-directory-sync-example/directory_sync/templates/directory_sync/users.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h2>Enterprise Ready</h2>
2323
<a href="https://workos.com/docs" target="_blank"><button class='button'>Documentation</button></a>
2424
<a href="https://workos.com/docs/reference" target="_blank"><button class='button'>API Reference</button></a>
2525
<a href="https://workos.com/blog" target="_blank"><button class='button'>Blog</button></a>
26-
<a href="javascript:history.back()"><button class="button">Home</button></a>
26+
<a href="javascript:history.back()"><button class="button">Back</button></a>
2727
</div>
2828
</div>
2929
<div class="logged_in_div_right">

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
urlpatterns = [
55
path('', views.get_home, name='home'),
6+
path('directory', views.get_directory, name='directory'),
67
path('users', views.get_directory_users, name='users'),
78
path('groups', views.get_directory_groups, name='groups'),
89
path('webhooks', views.webhooks, name='webhooks'),

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@
1212

1313
def get_home(request):
1414
print('request', request)
15-
return render(request, 'directory_sync/home.html')
15+
directories = workos.client.directory_sync.list_directories()
16+
directories = directories['data']
17+
return render(request, 'directory_sync/home.html', {"directories": directories})
18+
19+
def get_directory(request):
20+
directory_id = request.GET['id']
21+
directory = workos.client.directory_sync.get_directory(directory_id)
22+
return render(request, 'directory_sync/directory.html', {"directory_id": directory_id, "directory": directory})
1623

1724
def get_directory_users(request):
25+
directory_id = request.GET['id']
1826
users = workos.client.directory_sync.list_users(directory=directory_id)
1927
return render(request, 'directory_sync/users.html', {"users": users})
2028

2129

2230
def get_directory_groups(request):
31+
directory_id = request.GET['id']
2332
groups = workos.client.directory_sync.list_groups(directory=directory_id)
2433
return render(request, 'directory_sync/groups.html', {"groups": groups})
2534

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
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 = True
26+
DEBUG = False
2727

2828
ALLOWED_HOSTS = ['*']
2929

0 commit comments

Comments
 (0)