Skip to content

Commit

Permalink
Added api_key field to JWT to ignore expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
jontyms committed Aug 25, 2024
1 parent e993321 commit 173e2bd
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions app/util/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async def wrapper(request: Request, token: Optional[str], *args, **kwargs):
)
is_admin: bool = user_jwt.get("sudo", False)
creation_date: float = user_jwt.get("issued", -1)
api_key: bool = user_jwt.get("api_key", False)
except Exception as e:
if isinstance(e, jwt.JWTError) or isinstance(e, jwt.JWTClaimsError):
tr = Errors.generate(
Expand All @@ -58,15 +59,15 @@ async def wrapper(request: Request, token: Optional[str], *args, **kwargs):
"You are not a sudoer.",
essay="If you think this is an error, please try logging in again.",
)

if time.time() > creation_date + Settings().jwt.lifetime_sudo:
return Errors.generate(
request,
403,
"Session not new enough to verify sudo status.",
essay="Unlike normal log-in, non-bot sudoer sessions only last a day. This is to ensure the security of Hack@UCF member PII. "
"Simply re-log into Onboard to continue.",
)
if not api_key:
if time.time() > creation_date + Settings().jwt.lifetime_sudo:
return Errors.generate(
request,
403,
"Session not new enough to verify sudo status.",
essay="Unlike normal log-in, non-bot sudoer sessions only last a day. This is to ensure the security of Hack@UCF member PII. "
"Simply re-log into Onboard to continue.",
)

return await func(request, token, *args, **kwargs)

Expand Down

0 comments on commit 173e2bd

Please sign in to comment.