Skip to content

Commit 52d20ae

Browse files
awolfdenAdam Wolfman
andauthored
Add pagination to DSync app and update SDK versions in all apps (#27)
* Add pagination to dsync app and update all sdk versions * Remove print statements Co-authored-by: Adam Wolfman <[email protected]>
1 parent 9217a02 commit 52d20ae

File tree

11 files changed

+35
-23
lines changed

11 files changed

+35
-23
lines changed

python-flask-admin-portal-example/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ MarkupSafe==2.0.1
99
requests==2.26.0
1010
urllib3==1.26.7
1111
Werkzeug==2.0.1
12-
workos==1.16.0
12+
workos>=1.20.2
1313
python-dotenv
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Flask==2.0.0
2-
workos==1.16.0
2+
workos>=1.20.2
33
python-dotenv
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.formatting.provider": "black"
3+
}

python-flask-directory-sync-example/app.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
workos.api_key = os.getenv("WORKOS_API_KEY")
2020
workos.base_api_url = "http://localhost:5000/" if DEBUG else workos.base_api_url
21+
workos.client_id = os.getenv("WORKOS_CLIENT_ID")
2122
directory_id = os.getenv("DIRECTORY_ID")
2223

2324

@@ -30,13 +31,16 @@ def to_pretty_json(value):
3031

3132
@app.route("/")
3233
def home():
33-
directories = workos.client.directory_sync.list_directories()
34-
print(directories)
35-
directoryNames = []
36-
for i in directories["data"]:
37-
directoryNames.append(i["name"])
38-
print(directoryNames)
39-
return render_template("home.html", directories=directories)
34+
before = request.args.get("before")
35+
after = request.args.get("after")
36+
directories = workos.client.directory_sync.list_directories(
37+
before=before, after=after, limit=5, order=None
38+
)
39+
before = directories["listMetadata"]["before"]
40+
after = directories["listMetadata"]["after"]
41+
return render_template(
42+
"home.html", directories=directories["data"], before=before, after=after
43+
)
4044

4145

4246
@app.route("/directory")
@@ -66,7 +70,7 @@ def directory_groups():
6670
@app.route("/webhooks", methods=["GET", "POST"])
6771
def webhooks():
6872
if request.data:
69-
payload = request.get_data()
73+
payload = request.get_data().decode("utf-8")
7074
sig_header = request.headers["WorkOS-Signature"]
7175
response = workos_client.webhooks.verify_event(
7276
payload=payload, sig_header=sig_header, secret=os.getenv("WEBHOOKS_SECRET")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
Flask>=1.1.2
3-
workos>=1.16.0
3+
workos>=1.20.2
44
python-dotenv
55
flask_socketio

python-flask-directory-sync-example/templates/home.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ <h2>Python Flask Directory Sync Example App</h2>
1515
<hr style="width:100%">
1616
<a href="/webhooks" class="button width-95 button-outline">Test Webhooks</a>
1717
<hr style="width:100%">
18-
{% for i in directories.data %}
18+
{% for i in directories %}
1919
<a class="button width-95" href="/directory?id={{i['id']}}">{{ i['name'] }}</a>
2020
{% endfor %}
21-
21+
<hr style="width:100%">
22+
<div class="flex">
23+
{% if after %}
24+
<a href="/?after={{after}}"><button class="button button-outline">Previous</button></a>
25+
{% endif %}
26+
{% if before %}
27+
<a href="/?before={{before}}"><button class="button button-outline">Next</button></a>
28+
{% endif %}
29+
</div>
2230
</div>
2331
</body>
2432

python-flask-directory-sync-example/templates/users.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ <h2 class="home-hero-gradient">Enterprise Ready</h2>
3939
</div>
4040
<div class="logged_in_div_right">
4141
<div class="flex_column">
42-
<h2>Raw Users Object Details</h2>
42+
<h2>User Details</h2>
4343

4444
{% if users['data']|length > 0 %}
4545
<div class="text_box">
@@ -49,9 +49,10 @@ <h2>Raw Users Object Details</h2>
4949
<li class="even">{{user['first_name']}} {{user['last_name']}}: <code>{{user['username']}}</code>
5050
</li>
5151
{% else %}
52-
<li>{{user['first_name']}} {{user['last_name']}}: <code>{{user['username']}}</code>
52+
<li>{{user['first_name']}} {{user['last_name']}}: <code>{{user['username']}}</code></li>
5353
{% endif %}
5454
{% endfor %}
55+
5556
</ul>
5657
</div>
5758
{% else %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Flask==2.0.0
2-
workos==1.16.0
2+
workos>=1.20.2
33
python-dotenv
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Flask==2.0.0
2-
workos==1.16.0
2+
workos>=1.20.2
33
python-dotenv

python-flask-sso-example/app.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# Enter Connection ID here
2020

21-
CUSTOMER_CONNECTION_ID = "conn_01G90XQ07953ZADRSFVF1YFSXP"
21+
CUSTOMER_CONNECTION_ID = ""
2222

2323

2424
def to_pretty_json(value):
@@ -55,10 +55,6 @@ def auth():
5555
@app.route("/auth/callback")
5656
def auth_callback():
5757

58-
print(request.args.get("error"))
59-
print(request.args.get("error_description"))
60-
print(request.args.get("error_uri"))
61-
6258
code = request.args.get("code")
6359
profile = workos.client.sso.get_profile_and_token(code)
6460
p_profile = profile.to_dict()

0 commit comments

Comments
 (0)