- Python 3.x
- virtualenv package
- Docker (optional)
The Brivo API uses 3-legged OAuth2 authentication to connect applications securely. To use the API, users need to log in to the Brivo website actively. After the initial login, the server can refresh the token credential without direct user involvement.
Here is a high-level view of the flow
- Initially, the user's web browser is redirected to Brivo's website, where they log in and authorize the app.
- Once authenticated, they are redirected back to a preconfigured URL (any browser-accessible URL will work—cloud, local, http, or https) with an authorization code.
- The server then exchanges this code for an API token, granting secure access to the Brivo API on behalf of the user.
- Create a developer account at developer.brivo.com.
- This will provide you with an API key that you will need later.
- Obtain sandbox access to access.brivo.com.
- If you don't receive an email with your sandbox access credentials, contact Brivo support.
- Create an application to obtain a client ID and client secret:
- Log in to Access.
- Navigate to Configuration > Integrations.
- Click Generate API Token.
- Set the application type to 3-legged authentication.
- Set the redirect URI to http://localhost:8080/oauth_callback.
- Submit the form to get your client ID and client secret.
- Create a Virtual Environment
virtualenv -p python3 venv source venv/bin/activate
- Install Dependencies
pip install -r requirements.txt
- Configure Environment Variables
Set the following environment variables:
export BRIVO_APIKEY="your_api_key" export BRIVO_CLIENT_ID="your_client_id" export BRIVO_CLIENT_SECRET="your_client_secret" export BRIVO_REDIRECT_URI="http://localhost:8080/oauth_callback"
- Run Tests
- Just tests
PYTHONPATH=. pytest
- Coverage report
PYTHONPATH=. pytest --cov=app --cov-report html
- Build&Run Docker Container
- Development mode
PYTHONPATH=. python app/webapp.py --host 127.0.0.1 --port 8080 --debug
- Production mode
docker build -t your_image_name . docker run \ -e BRIVO_APIKEY=$BRIVO_APIKEY \ -e BRIVO_CLIENT_ID=$BRIVO_CLIENT_ID \ -e BRIVO_CLIENT_SECRET=$BRIVO_CLIENT_SECRET \ -e BRIVO_REDIRECT_URI=$BRIVO_REDIRECT_URI \ --rm --name brivo-app -p 8080:8080 \ your_image_name