Skip to content

Commit

Permalink
Output access token expiration time.
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Pigorsch committed Jun 18, 2020
1 parent 94c2398 commit f6a0bb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def set_points_of_interest(self, pois):
self.pois = pois

def check_access(self):
if time.time() > self.authdata["expires_at"]:
now = datetime.datetime.fromtimestamp(time.time())
expires_at = datetime.datetime.fromtimestamp(self.authdata["expires_at"])
print(f'Access token valid until {expires_at} (now is {now})')
if now >= expires_at:
print("Refreshing access token")
response = self.client.refresh_access_token(
client_id=self.config["client_id"],
Expand All @@ -50,6 +53,8 @@ def check_access(self):
self.authdata["access_token"] = response["access_token"]
self.authdata["refresh_token"] = response["refresh_token"]
self.authdata["expires_at"] = response["expires_at"]
expires_at = datetime.datetime.fromtimestamp(self.authdata["expires_at"])
print(f'New access token will expire at {expires_at}')
self.authdata_changed = True

self.client.access_token = self.authdata["access_token"]
Expand Down
6 changes: 3 additions & 3 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.0/css/bulma.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.6.0/dist/leaflet.css">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="style.css?CACHEBUSTER">
</head>

<body>
Expand Down Expand Up @@ -82,7 +82,7 @@ <h2>Info</h2>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.6.0/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/polyline-encoded@0.0.9/Polyline.encoded.js"></script>
<script src="activities.js"></script>
<script src="app.js"></script>
<script src="activities.js?CACHEBUSTER"></script>
<script src="app.js?CACHEBUSTER"></script>
</body>
</html>

0 comments on commit f6a0bb5

Please sign in to comment.