Skip to content

Commit 53be174

Browse files
awolfdenAdam Wolfman
andauthored
Update Flask apps with caveat regarding port use with Mac OS Monterey and removed buggy user image logic from logged in page on SSO app (#5)
Co-authored-by: Adam Wolfman <[email protected]>
1 parent c02dc3a commit 53be174

File tree

8 files changed

+34
-24
lines changed

8 files changed

+34
-24
lines changed

python-flask-admin-portal-example/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ An example Flask application demonstrating how to use the [WorkOS Python SDK](ht
7070
(env) $ echo $WORKOS_CLIENT_ID
7171
```
7272
73-
10. Update the Admin Portal Redirect Link in the "Configuration" page of your WorkOS Dashboard. The URL should be http://localhost:5000.
73+
10. Update the Admin Portal Redirect Link in the "Configuration" page of your WorkOS Dashboard. The URL should be http://localhost:5000. If you are using Mac OS Monterey, set this to localhost:5001.
7474
7575
After an Admin Portal user creates an SSO connection using the Admin Portal, they need to be redirected to a webpage within your application (usually this webpage confirms successful creation of the connection). To configure which webpage this is, enter the webpage’s URL in the Configuration section of your WorkOS dashboard under the “Admin Portal Redirect Link” header. For production usage this URL must begin with HTTPS, but for development purposes the URL can begin with HTTP.
7676
@@ -81,6 +81,11 @@ After an Admin Portal user creates an SSO connection using the Admin Portal, the
8181
(env) $ flask run
8282
```
8383
84+
If you are using Mac OS Monterey, port 5000 is not available and you'll need to start the app on a different port with this slightly different command.
85+
```bash
86+
(env) $ flask run -p 5001
87+
```
88+
8489
You'll know the server is running when you see no errors in the CLI, and output similar to the following is displayed:
8590
8691
```bash
@@ -92,7 +97,7 @@ After an Admin Portal user creates an SSO connection using the Admin Portal, the
9297
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
9398
```
9499
95-
Navigate to `localhost:5000` in your web browser to view the homepage of the Admin Portal example app. Enter the name of the new Organization to be created and the names of all of the Organization's associated domains.
100+
Navigate to `localhost:5000`, or `localhost:5001` depending on which port you launched the server, in your web browser to view the homepage of the Admin Portal example app. Enter the name of the new Organization to be created and the names of all of the Organization's associated domains.
96101

97102
- The Organization must be a new Organization that doesn't yet exist in your WorkOS dashboard
98103
- The domains should be entered as space-separated values, e.g. "domain1.com domain2.com domain3.com"

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ If you get stuck, please reach out to us at [email protected] so we can help.
8989
flask run
9090
```
9191

92-
11. Once the server is running, navigate to http://localhost:5000 to view the home page of the app where you can then select the view for users or groups.
92+
If you are using Mac OS Monterey, port 5000 is not available and you'll need to start the app on a different port with this slightly different command.
93+
```bash
94+
(env) $ flask run -p 5001
95+
```
96+
97+
11. Once the server is running, navigate to `http://localhost:5000`, or `http://localhost:5001` depending on which port you launched the server, to view the home page of the app where you can then select the view for users or groups.
9398
9499
- The `/users` URL corresponds to the WorkOS API's [List Directory Users endpoint](https://workos.com/docs/reference/directory-sync/user/list)
95100
- The `/groups` URL corresponds to the WorkOS API's [List Directory Groups endpoint](https://workos.com/docs/reference/directory-sync/group/list)

python-flask-magic-link-example/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ An example Flask application demonstrating how to use the [WorkOS Python SDK](ht
7676
(env) $ flask run
7777
```
7878

79+
If you are using Mac OS Monterey, port 5000 is not available and you'll need to start the app on a different port with this slightly different command.
80+
```bash
81+
(env) $ flask run -p 5001
82+
```
83+
7984
You'll know the server is running when you see no errors in the CLI, and output similar to the following is displayed:
8085

8186
```bash
@@ -87,18 +92,18 @@ An example Flask application demonstrating how to use the [WorkOS Python SDK](ht
8792
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
8893
```
8994

90-
Navigate to `localhost:5000` in your web browser. You should see a "Login" button.
95+
Navigate to `localhost:5000`, or `localhost:5001` depending on which port you launched the server, in your web browser. You should see a "Login" button.
9196

9297
You can stop the local Flask server for now by entering `CTRL + c` on the command line.
9398

9499

95100
## Magic Link Setup with WorkOS
96101

97-
Change the default REDIRECT_URI value in the "Configuration" page of your WorkOS dashboard to http://localhost:5000/success.
102+
Change the default REDIRECT_URI value in the "Configuration" page of your WorkOS dashboard to `http://localhost:5000/success`, or `http://localhost:5001/success` depending on which port you launched the server.
98103

99104
## Testing the Integration
100105

101-
1. Naviagte to http://localhost:5000 to test out the Magic Link flow!
106+
1. Naviagte to http://localhost:5000, or `http://localhost:5001/success` depending on which port you launched the server, to test out the Magic Link flow!
102107

103108
## Need help?
104109

python-flask-sso-example/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,18 @@ An example Flask application demonstrating how to use the [WorkOS Python SDK](ht
7171
(env) $ echo $WORKOS_CLIENT_ID
7272
```
7373

74-
10. In `python-flask-sso-example/app.py` change the `CUSTOMER_EMAIL_DOMAIN` string value to an email domain that makes sense for your testing purposes if the default `gmail.com` isn't relevant. If you'd like to establish auth connection via Connection_ID instead, please change the `CUSTOMER_CONNECTION_ID` to your organization's connectionID.
74+
10. In `python-flask-sso-example/app.py` change the `CUSTOMER_CONNECTION_ID` string value to the connection you will be testing the login for. This can be found in your WorkOS Dashboard.
7575

7676
11. The final setup step is to start the server.
7777
```bash
7878
(env) $ flask run
7979
```
8080

81+
If you are using Mac OS Monterey, port 5000 is not available and you'll need to start the app on a different port with this slightly different command.
82+
```bash
83+
(env) $ flask run -p 5001
84+
```
85+
8186
You'll know the server is running when you see no errors in the CLI, and output similar to the following is displayed:
8287

8388
```bash
@@ -89,7 +94,7 @@ An example Flask application demonstrating how to use the [WorkOS Python SDK](ht
8994
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
9095
```
9196

92-
Navigate to `localhost:5000` in your web browser. You should see a "Login" button. If you click this link, you'll be redirected to an HTTP `404` page because we haven't set up SSO yet!
97+
Navigate to `localhost:5000`, or `localhost:5001` depending on which port you launched the server, in your web browser. You should see a "Login" button. If you click this link, you'll be redirected to an HTTP `404` page because we haven't set up SSO yet!
9398

9499
You can stop the local Flask server for now by entering `CTRL + c` on the command line.
95100

@@ -104,15 +109,15 @@ If you get stuck, please reach out to us at [email protected] so we can help.
104109

105110
## Testing the Integration
106111

107-
1. Naviagte to the `python-flask-sso-example` directory. Source the virtual environment we created earlier, if it isn't still activated from the steps above. Start the Flask server locally.
112+
12. Naviagte to the `python-flask-sso-example` directory. Source the virtual environment we created earlier, if it isn't still activated from the steps above. Start the Flask server locally.
108113

109114
```bash
110115
$ cd ~/Desktop/python-flask-sso-example/
111116
$ source env/bin/activate
112117
(env) $ flask run
113118
```
114119

115-
Once running, navigate to http://localhost:5000 to test out the SSO workflow.
120+
Once running, navigate to `localhost:5000`, or `localhost:5001` depending on which port you launched the server, to test out the SSO workflow.
116121

117122
Hooray!
118123

python-flask-sso-example/app.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414
workos.project_id = os.getenv('WORKOS_CLIENT_ID')
1515
workos.base_api_url = 'http://localhost:7000/' if DEBUG else workos.base_api_url
1616

17-
# There'd realistically be persons with different domains trying to sign in,
18-
# where some may have SSO and some may not. This example assumes only workos.com
19-
# domains with SSO setup.
20-
CUSTOMER_EMAIL_DOMAIN = 'gmail.com'
21-
CUSTOMER_CONNECTION_ID = 'conn_01FH8T97XSAF3TV249GHESFTED'
17+
# Enter Connection ID here
18+
CUSTOMER_CONNECTION_ID = 'xxx'
2219

2320
@app.route('/')
2421
def login():
@@ -28,7 +25,6 @@ def login():
2825
def auth():
2926

3027
authorization_url = workos.client.sso.get_authorization_url(
31-
domain = CUSTOMER_EMAIL_DOMAIN,
3228
redirect_uri = url_for('auth_callback', _external=True),
3329
state = {},
3430
connection = CUSTOMER_CONNECTION_ID
@@ -45,12 +41,6 @@ def auth_callback():
4541
p_profile = profile.to_dict()
4642
first_name = p_profile['profile']['first_name']
4743

48-
if "picture" in p_profile['profile']['raw_attributes']:
49-
image = p_profile['profile']['raw_attributes']['picture']
50-
else:
51-
image = "../static/images/workos_logo.png"
52-
5344
raw_profile = p_profile['profile']
5445

55-
56-
return render_template('login_successful.html', first_name=first_name, image=image, raw_profile=raw_profile)
46+
return render_template('login_successful.html', first_name=first_name, raw_profile=raw_profile)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Flask==2.0.0
22
workos==1.2.0
3+
python-dotenv
17.2 KB
Loading

python-flask-sso-example/templates/login_successful.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<body class="container_success">
66
<div class="logged_in_nav">
77
<div class="flex">
8-
<img src={{image}} alt="Profile Image">
98
<p>You're logged in {{first_name}}, welcome!</p>
109
</div>
1110
<div>

0 commit comments

Comments
 (0)