Merge pull request #179 from MagicRB/fix_installation_token_renewal

Fix GitHub `InstallationToken` renewal.
This commit is contained in:
Jörg Thalheim 2024-06-13 10:54:59 +02:00 committed by GitHub
commit aeddb4809d
Failed to generate hash of commit

View file

@ -41,7 +41,9 @@ class InstallationToken(RepoToken):
token = InstallationToken._create_installation_access_token( token = InstallationToken._create_installation_access_token(
jwt_token, installation_id jwt_token, installation_id
).json()["token"] ).json()["token"]
expiration = datetime.now(tz=UTC) + InstallationToken.GITHUB_TOKEN_LIFETIME expiration = (
datetime.now(tz=UTC) + InstallationToken.GITHUB_TOKEN_LIFETIME * 0.8
)
return token, expiration return token, expiration
@ -72,7 +74,7 @@ class InstallationToken(RepoToken):
return f"%(secret:github-token-{self.installation_id})" return f"%(secret:github-token-{self.installation_id})"
def verify(self) -> None: def verify(self) -> None:
if datetime.now(tz=UTC) - self.expiration > self.GITHUB_TOKEN_LIFETIME * 0.8: if datetime.now(tz=UTC) > self.expiration:
self.token, self.expiration = InstallationToken._generate_token( self.token, self.expiration = InstallationToken._generate_token(
self.jwt_token, self.installation_id self.jwt_token, self.installation_id
) )