-
Hello, I'm trying to integrate flask-smorest with flask-security-too for a password-based authentication app and after using flask-smorest Code
from flask_security import auth_required, login_required, current_user
from flask_smorest import Blueprint, abort
from .usering.models.user import User
from .usering.models.role import Role
from .usering.models.user_role import UserRole
blp = Blueprint('auth', __name__, description='Endpoints for authentication')
@blp.route('/auth')
@auth_required()
class loginUser(MethodView):
@blp.doc(description='Use this route to login as admin or user.')
def get(self):
pass
@blp.doc(description='Use this route to login as admin or user.')
def post(self):
print(current_user.is_anonymous)
return {"status": "OK"}
class User(BaseDBModel, UserMixin):
"""The user table in the database."""
__tablename__ = "user_account"
id = Column(Integer(), primary_key=True)
email = Column(String(255), unique=True)
username = Column(String(255), unique=True, nullable=True)
password = Column(String(255), nullable=False)
fs_uniquifier = Column(String(255), unique=True, nullable=False)
active = Column(Boolean())
roles = relationship(
"Role", secondary="user_role", backref=backref("users", lazy="dynamic")
) SwaggerError
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can't decorate a class since that will cause the class itself to be returned (which is what the error is saying). ` class MyView(MethodView):
|
Beta Was this translation helpful? Give feedback.
You can't decorate a class since that will cause the class itself to be returned (which is what the error is saying).
I think you are using Flask.views - in that case something like this should work:
` class MyView(MethodView):
decorators = [auth_required("token", "session")]