Skip to content

Commit bbf4c5f

Browse files
Adam WolfmanAdam Wolfman
authored andcommitted
first commit
1 parent 0cdbe1e commit bbf4c5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3373
-2
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1-
# python-django-example-applications
2-
Example applications demonstrating the use of the WorkOS Python SDK to support SSO, Directory Sync, Admin Portal, and Magic Link.
1+
*# Python-Django Example Appplications powered by WorkOS
2+
*
3+
Example applications demonstrating to use the [WorkOS Python SDK](_https://github.com/workos-inc/workos-python_) for SSO, Directory Sync, Admin Portal and Magic Link.
4+
5+
*## For more information, please see the following guides:
6+
*
7+
* [Single Sign-On](_https://workos.com/docs/sso/guide_)
8+
* [Directory Sync](_https://workos.com/docs/directory-sync/guide_)
9+
* [Admin Portal](_https://workos.com/docs/admin-portal/guide_)
10+
* [Magic Link](_https://workos.com/docs/magic-link/guide_)
11+
12+
* [API Reference](_https://workos.com/docs/reference_)
13+
14+
*## Need help?
15+
*
16+
If you get stuck and aren't able to resolve the issue by reading our [WorkOS Python SDK documentation](_https://docs.workos.com/sdk/python_) or [API reference](_https://workos.com/docs/reference_), you can reach out to us at [email protected] and we'll lend a hand!
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
.DS_Store
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 erin-workos
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# python-django-admin-portal-example
2+
A basic Django app that uses the [WorkOS Python SDK](https://github.com/workos-inc/workos-python) to access the Admin Portal.
3+
4+
## Prerequisites
5+
- Python 3.6+
6+
7+
8+
### Clone Directory
9+
10+
1. In your CLI, navigate to the directory into which you want to clone this git repo.
11+
```bash
12+
$ cd ~/Desktop/
13+
```
14+
15+
2. Clone the main git repo for these Python example apps using your preferred secure method (HTTPS or SSH).
16+
```bash
17+
# HTTPS
18+
$ git clone https://github.com/workos-inc/python-django-example-applications.git
19+
```
20+
21+
or
22+
23+
```bash
24+
# SSH
25+
$ git clone [email protected]:workos-inc/python-django-example-applications.git
26+
```
27+
28+
3. Navigate to the Admin Portal example app within the cloned repo.
29+
```bash
30+
$ cd python-django-example-applications/python-django-admin-portal-example
31+
````
32+
33+
### Install Dependencies
34+
35+
4. Create and source a Python virtual environment. You should then see `(env)` at the beginning of your command-line prompt.
36+
```bash
37+
$ python3 -m venv env
38+
$ source env/bin/activate
39+
(env) $
40+
```
41+
42+
5. Move in to the app directory and install the cloned app's dependencies. There are two workos_django directories in this repo, however you'll want to be in the top level directory that includes the manage.py file for this step.
43+
```bash
44+
(env) $ cd workos_django
45+
(env) $ pip install -r requirements.txt
46+
```
47+
48+
### Set Environment Variables
49+
50+
6. Obtain and make note of the following values. In the next step, these will be set as environment variables.
51+
- Your [WORKOS_API_KEY](https://dashboard.workos.com/api-keys)
52+
- Your `WORKOS_CLIENT_ID`, in the format `client_<random-alphanumeric-string>`, retrievable from WorkOS dashboard under Configuration.
53+
54+
7. Ensure you're in the root app directory for the example app, `workos_django/` where the `manage.py` file resides. 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.)
55+
```bash
56+
(env) $ touch .env
57+
(env) $ nano .env
58+
```
59+
60+
8. Once the Nano text editor opens, you can directly edit the `.env` file by listing the environment variables:
61+
```bash
62+
export WORKOS_API_KEY=<value found in step 6>
63+
export WORKOS_CLIENT_ID=<value found in step 6>
64+
```
65+
66+
To exit the Nano text editor, type `CTRL + x`. When prompted to "Save modified buffer", type `Y`, then press the `Enter` or `Return` key.
67+
68+
9. Source the environment variables so they are accessible to the operating system.
69+
```bash
70+
(env) $ source .env
71+
```
72+
73+
You can ensure the environment variables were set correctly by running the following commands. The output should match the corresponding values.
74+
```bash
75+
(env) $ echo $WORKOS_API_KEY
76+
(env) $ echo $WORKOS_CLIENT_ID
77+
```
78+
79+
10. Run the Django migrations. Again, ensure you're in the `workos_django/` directory where the `manange.py` file is.
80+
```bash
81+
(env) $ python3 manage.py migrate
82+
```
83+
84+
You should see output like:
85+
```bash
86+
Operations to perform:
87+
Apply all migrations: admin, auth, contenttypes, sessions
88+
Running migrations:
89+
Applying contenttypes.0001_initial... OK
90+
Applying auth.0001_initial... OK
91+
. . .
92+
```
93+
94+
11. Update the Admin Portal Redirect Link in the Configuration page of your WorkOS Dashboard
95+
96+
To configure the page where the user will be redirected after completing the organization creation/connection through Admin Portal, enter the url in the Admin Portal Redirect Link in the Configuration page of your WorkOS dashboard. This URL must be https.
97+
98+
99+
## Start the server
100+
101+
12. Start the server.
102+
103+
To serve static files in development while still having `debug=True` in settings.py to able to send requests to WorkOS, be sure to include the `--insecure` flag when starting the server locally.
104+
```bash
105+
(env) $ python3 manage.py runserver --insecure
106+
```
107+
108+
You'll know the server is running when you see no errors in the CLI, and output similar to the following is displayed:
109+
110+
```bash
111+
Watching for file changes with StatReloader
112+
Performing system checks...
113+
114+
System check identified no issues (0 silenced).
115+
March 18, 2021 - 04:54:50
116+
Django version 3.1.7, using settings 'workos_django.settings'
117+
Starting development server at http://127.0.0.1:8000/
118+
Quit the server with CONTROL-C.
119+
```
120+
121+
13. Once the server is running, navigate to http://localhost:8000 to view the home page of the app. Here you'll enter the name of the Organization to be created, and all associated domains. The domains should be entered as space-separated values, e.g. `domain1.com domain2.com domain3.com`
122+
123+
Note that the organization must be a new organization that does not yet exists in your WorkOS dashboard.
124+
125+
14. Click on the button to create your Organization and log in to the Admin Portal workflow!
126+
127+
## Need help?
128+
129+
When you clone this repo, the `DEBUG` setting is `False` by default in `app.py`. You can set `DEBUG = True` if you need to troubleshoot something during the tutorial, but you must use `DEBUG = False` in order to successfully connect to the WorkOS API.
130+
131+
If you get stuck and aren't able to resolve the issue by reading our API reference or tutorials, please reach out to us at [email protected] and we'll help you out.

python-django-admin-portal-example/workos_django/admin_portal/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AdminPortalConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'admin_portal'

python-django-admin-portal-example/workos_django/admin_portal/migrations/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

0 commit comments

Comments
 (0)