rscarrera27 / Sanic-JWT-Extended

⚡️An open source Sanic extension that provides "extended" JWT support
https://sanic-jwt-extended.seonghyeon.dev
MIT License
35 stars 8 forks source link

Get unexpected keyword argument 'token' while using decorator in class #31

Closed krishnajangid closed 4 years ago

krishnajangid commented 4 years ago

While using decorators in class-based we get an error.

TypeError: post() got an unexpected keyword argument 'token'

class RestView(HTTPMethodView):
    decorators = [jwt_required()]

    async def post(self, request):
        self.__request_data = request.json
        print("POST API")
        return {}

app.add_route(Test.as_view(), '/test')

And another thing is while initializing role for a user it takes only one role.

access_token = JWT.create_access_token(identity=username, role='staff')

Actually it should take a list of roles.

access_token = JWT.create_access_token(identity=username, role=['staff', 'admin'])
rscarrera27 commented 4 years ago

You must specify token parameter in your handler methods.

https://sanic-jwt-extended.seonghyeon.dev/usage/basic.html#protect-views

rscarrera27 commented 4 years ago

And taking a list of roles is not designed behavior. 🤔 I have to take a look for this. and I want to keep the built-in function as simple as possible, so if you want a complex access control, you may have to make your own code that interacts with JWT object.

krishnajangid commented 4 years ago

Thanks, @NovemberOscar. The token issue is resolved.