This following steps are instructions to launch and view a simple Python Flask application that authenticates with Procore's API using the OAuth 2.0 Authorization Code Grant Type flow. The application is configured to access either Procore's production environment or Procore's developer sandbox environment.
THIS REPOSITORY IS FOR TRAINING PURPOSES ONLY.
- Clone this repository
- If you do not have Python 3, Download and Install Python 3 (Recommended version >=3.7) from
https://www.python.org/downloads/
. If you are unsure which version you have, typepython3 --version
orpython --version
into the terminal. - If you do not have
pip
currently installed, runpython3 -m pip install -U pip
. If you do have pip installed, make surepip
is referncing Python 3 by - If you have
pipenv
installed skip this step, otherwise runpip install pipenv
. It is important that pipenv - Navigate to the
python-oauth-sample
folder in the command line and runpipenv install
. - Navigate to the
.env.example
file in the root directory of the project. Rename the file to.env
.
Within this file, configure your application's Client ID, Client Secret, Redirect URI, OAuth URL, and Base URL in order to save these as the application's environment variables:
* CLIENT_ID:
* CLIENT_SECRET:
* REDIRECT_URI: http://localhost:3000/users/home
* OAUTH_URL: https://login.procore.com
* BASE_URL: https://api.procore.com
* Client ID and Client Secret values are provided when [creating an application](https://developers.procore.com/documentation/new-application) in the Procore Developer Portal. The redirect URI above should be added to your application, which can be done on your application's home page.
* The BASE_URL and the OAUTH_URL will depend on which environment you're working accessing. If you're working in the production environment, the OAUTH_URL will be https://login.procore.com and the BASE_URL will be https://api.procore.com. For the sandbox environment, both the OAUTH_URL and the BASE_URL should be set to https://sandbox.procore.com.
* After these values have been configured within the `.env` file, make sure to save your changes.
- Remember to add the REDIRECT_URI to the to your application's configuration page.
- From the command line,
pipenv run python3 app.py
while you are in thepython-oauth-sample
folder. Open a web browser and navigate to "localhost:3000" using the address bar. - The landing page will include a button that says, "Sign In to Procore". Click this button and enter your Procore email address/password.
- After authenticating with Procore, you will be redirected back to the sample application. This page will include a table containing the first and last five characters of both your access token and your refresh token. In addition, there will be timestamps corresponding to when the access token was generated and when it expires (2 hours after generation).
- To access the data returned by the Show User Info endpoint, click on the "Show User Information" button on the home page.
- To refresh your access token, click on the "Refresh Access Token" button. Notice that the corresponding values will be updated in the table on the home page.
- To revoke your access token, click on the "Revoke Access Token" button. This will remove your access token and return you to the sign in homepage. If you have any questions regarding this application's code or functionality, please reach out to [email protected].