From e1f8f89a9bbfd608fe7c24566c1aa3b6c9fff438 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 15 Apr 2021 21:19:20 +0200 Subject: [PATCH] fixing auth for token --- ereuse_devicehub/auth.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/auth.py b/ereuse_devicehub/auth.py index 5820c326..19f6e5fa 100644 --- a/ereuse_devicehub/auth.py +++ b/ereuse_devicehub/auth.py @@ -3,12 +3,17 @@ from teal.auth import TokenAuth from teal.db import ResourceNotFound from werkzeug.exceptions import Unauthorized -from ereuse_devicehub.resources.user.models import User +from ereuse_devicehub.resources.user.models import User, Session class Auth(TokenAuth): def authenticate(self, token: str, *args, **kw) -> User: try: - return User.query.filter_by(token=token).one() + user = User.query.filter_by(token=token).first() + if user: + return user + + ses = Session.query.filter_by(token=token).one() + return ses.user except (ResourceNotFound, DataError): raise Unauthorized('Provide a suitable token.')