Skip to content

Commit

Permalink
oauth: set token creation time before we fetch it
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejbudai committed Jun 29, 2022
1 parent 7da87b8 commit e9e4062
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions plugins/builder/osbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ class OAuth2(requests.auth.AuthBase):
"""

class Token:
def __init__(self, data):
def __init__(self, data, created):
self.data = data["access_token"]
self.type = data["token_type"]
self.expires_in = int(data["expires_in"])
self.scope = data.get("scope")

self.created = time.time()
self.created = created

@property
def expired(self) -> bool:
Expand All @@ -299,6 +299,7 @@ def token_expired(self) -> bool:
return not self.token or self.token.expired

def fetch_token(self, http: requests.Session):
now = time.time()
data = {
"grant_type": "client_credentials",
"client_id": self.id,
Expand All @@ -312,7 +313,7 @@ def fetch_token(self, http: requests.Session):
raise koji.GenericError(msg) from None

token_data = res.json()
self.token = self.Token(token_data)
self.token = self.Token(token_data, now)

def __call__(self, r: requests.Request):
"""Called by requests to obtain authorization"""
Expand Down

0 comments on commit e9e4062

Please sign in to comment.