Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

An example Flask application demonstrating how to use the WorkOS Python SDK to support Directory Sync.

License

Notifications You must be signed in to change notification settings

workos/python-flask-directory-sync-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-flask-directory-sync-example

A basic Flask app that uses the WorkOS Python SDK to support Directory Sync.

Prerequisites

  • Python 3.6+

Directory Sync Setup with WorkOS

First, follow the Create a New Directory Connection step in the WorkOS Directory Sync guide.

If you get stuck, please reach out to us at support@workos.com so we can help.

Flask Project Setup

Clone Directory

  1. In your CLI, navigate to the directory into which you want to clone this git repo.

    $ cd ~/Desktop/
  2. Clone this git repo using your preferred secure method (HTTPS or SSH).

    # HTTPS
    $ git clone https://github.com/workos-inc/python-flask-directory-sync-example.git

or

# SSH
$ git clone git@github.com:workos-inc/python-flask-directory-sync-example.git

Install Dependencies

  1. Navigate to the cloned repo.

    $ cd python-flask-directory-sync-example
  2. Create and source a Python virtual environment. You should then see (env) at the beginning of your command-line prompt.

    $ python3 -m venv env
    $ source env/bin/activate
    (env) $
  3. Install the cloned app's dependencies.

    (env) $ pip install -r requirements.txt

Set Environment Variables

  1. Obtain and make note of the following values. In the next step, these will be set as environment variables.

    • Your WorkOS API key
    • Your DIRECTORY_ID, in the format directory_<random-alphanumeric-string>, retrievable from the URL in the Directory Sync area of the WorkOS dashboard:
  2. Ensure you're in the root directory for the example app, python-flask-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.)

    (env) $ touch .env
    (env) $ nano .env
  3. Once the Nano text editor opens, you can directly edit the .env file by listing the environment variables:

    export WORKOS_API_KEY=<value found in step 6>
    export DIRECTORY_ID=<value found in step 6>

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

  4. Source the environment variables so they are accessible to the operating system.

    (env) $ source .env

    You can ensure the environment variables were set correctly by running the following commands. The output should match the corresponding values.

    (env) $ echo $WORKOS_API_KEY
    (env) $ echo $DIRECTORY_ID

Start the server

  1. Use this command to run the app:

    flask run
  2. 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. Alternatively you could also view these directly using the following url's: http://localhost:5000/users and http://localhost:5000/groups.

Need help?

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.

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 support@workos.com and we'll help you out.

About

An example Flask application demonstrating how to use the WorkOS Python SDK to support Directory Sync.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •