Skip to content

Commit aada7f1

Browse files
authored
🐛 Fix: app auth token expiration edge case (#219)
1 parent 59bd6d0 commit aada7f1

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

githubkit/auth/app.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,13 @@ def sync_auth_flow(
212212
response.read()
213213
response = self._parse_installation_auth_response(response)
214214
token = response.parsed_data.token
215-
expire = datetime.strptime(
216-
response.parsed_data.expires_at, "%Y-%m-%dT%H:%M:%SZ"
217-
).replace(tzinfo=timezone.utc) - datetime.now(timezone.utc)
215+
expire = (
216+
datetime.strptime(
217+
response.parsed_data.expires_at, "%Y-%m-%dT%H:%M:%SZ"
218+
).replace(tzinfo=timezone.utc)
219+
- datetime.now(timezone.utc)
220+
- timedelta(minutes=1)
221+
)
218222
cache.set(key, token, expire)
219223
request.headers["Authorization"] = f"token {token}"
220224
yield request
@@ -250,9 +254,13 @@ async def async_auth_flow(
250254
await response.aread()
251255
response = self._parse_installation_auth_response(response)
252256
token = response.parsed_data.token
253-
expire = datetime.strptime(
254-
response.parsed_data.expires_at, "%Y-%m-%dT%H:%M:%SZ"
255-
).replace(tzinfo=timezone.utc) - datetime.now(timezone.utc)
257+
expire = (
258+
datetime.strptime(
259+
response.parsed_data.expires_at, "%Y-%m-%dT%H:%M:%SZ"
260+
).replace(tzinfo=timezone.utc)
261+
- datetime.now(timezone.utc)
262+
- timedelta(minutes=1)
263+
)
256264
await cache.aset(key, token, expire)
257265
request.headers["Authorization"] = f"token {token}"
258266
yield request

0 commit comments

Comments
 (0)