Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added token refresh feature #62

Merged
merged 4 commits into from
Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def retrieve_site_from_device_id(device_id, site_devices_data):
# We import the cameras's positions from the API that locates the cameras
# Fetching the response in a variable
response = api_client.get_sites()
# Check token expiration
if response.status_code == 422:
api_client.refresh_token(cfg.API_LOGIN, cfg.API_PWD)
response = api_client.get_sites()

# Getting the json data out of the response
camera_positions = response.json()
Expand Down
8 changes: 7 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@
app.config.suppress_callback_exceptions = True
server = app.server # Gunicorn will be looking for the server attribute of this module

response = requests.get('https://api.pyronear.org/devices/', headers=api_client.headers)
# Check token expiration
if response.status_code == 422:
api_client.refresh_token(cfg.API_LOGIN, cfg.API_PWD)
response = requests.get('https://api.pyronear.org/devices/', headers=api_client.headers)

# We create a rough layout, filled with the content of the homepage/alert page
app.layout = html.Div(
[
Expand All @@ -111,7 +117,7 @@
dcc.Store(
id="devices_data_storage",
storage_type="session",
data=requests.get('https://api.pyronear.org/devices/', headers=api_client.headers).json()
data=response.json()
),

# Main interval that fetches API alerts data
Expand Down