Merge pull request #3422 from jtschladen/fix-apikey-ttl

Fix TTL calculation for API keys
This commit is contained in:
Jasmine Schladen 2021-02-17 09:12:56 -08:00 committed by GitHub
commit 697b1ad878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 4 deletions

View File

@ -75,7 +75,7 @@ def create_token(user, aid=None, ttl=None):
if ttl == -1:
del payload["exp"]
else:
payload["exp"] = ttl
payload["exp"] = datetime.utcnow() + timedelta(days=ttl)
token = jwt.encode(payload, current_app.config["LEMUR_TOKEN_SECRET"])
return token
@ -116,9 +116,8 @@ def login_required(f):
return dict(message="Token has been revoked"), 403
if access_key.ttl != -1:
current_time = datetime.utcnow()
expired_time = datetime.fromtimestamp(
access_key.issued_at + access_key.ttl
)
# API key uses days
expired_time = datetime.fromtimestamp(access_key.issued_at) + timedelta(days=access_key.ttl)
if current_time >= expired_time:
return dict(message="Token has expired"), 403