This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/auth.py

15 lines
472 B
Python
Raw Normal View History

2018-04-27 17:16:43 +00:00
from sqlalchemy.exc import DataError
2018-09-07 10:38:02 +00:00
from teal.auth import TokenAuth
from teal.db import ResourceNotFound
2018-04-27 17:16:43 +00:00
from werkzeug.exceptions import Unauthorized
from ereuse_devicehub.resources.user.models import User
2018-04-10 15:06:39 +00:00
class Auth(TokenAuth):
2018-04-27 17:16:43 +00:00
def authenticate(self, token: str, *args, **kw) -> User:
try:
return User.query.filter_by(token=token).one()
except (ResourceNotFound, DataError):
raise Unauthorized('Provide a suitable token.')