From 46f6ec05aaee70bee1241eeadd90cdcddde1255c Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 26 Mar 2020 22:26:42 +0100 Subject: [PATCH] [!] Check if a token has expired before authenticating --- royalnet/backpack/tables/tokens.py | 2 +- royalnet/constellation/api/apidata.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/royalnet/backpack/tables/tokens.py b/royalnet/backpack/tables/tokens.py index f9e80cd8..eaa58a2b 100644 --- a/royalnet/backpack/tables/tokens.py +++ b/royalnet/backpack/tables/tokens.py @@ -51,5 +51,5 @@ class Token: } @classmethod - async def authenticate(cls, alchemy, session, token: str) -> "Token": + async def find(cls, alchemy, session, token: str) -> "Token": return await ru.asyncify(session.query(alchemy.get(cls)).filter_by(token=token).one_or_none) diff --git a/royalnet/constellation/api/apidata.py b/royalnet/constellation/api/apidata.py index a8915c50..0a6bf724 100644 --- a/royalnet/constellation/api/apidata.py +++ b/royalnet/constellation/api/apidata.py @@ -18,9 +18,11 @@ class ApiData(dict): raise MissingParameterError(f"Missing '{key}'") async def token(self) -> Token: - token = await Token.authenticate(self.star.alchemy, self.session, self["token"]) + token = await Token.find(self.star.alchemy, self.session, self["token"]) if token is None: raise ForbiddenError("'token' is invalid") + if token.expired: + raise ForbiddenError("Login token has expired") return token async def user(self) -> User: