ahopkins / sanic-jwt

Authentication, JWT, and permission scoping for Sanic
http://sanic-jwt.readthedocs.io
MIT License
242 stars 52 forks source link

How to completly modify default responses endpoints ? #204

Closed JeanMenage closed 3 years ago

JeanMenage commented 3 years ago

Hi ! First of all, thansk a lot for your work, it's really helpfull. I've seen that default responses endpoints can be changed however for exemple with the verify endpoint I would like to be able to remove the line '"valid":true', I can't find how to do it or if that's possible tho. Thanks !

ahopkins commented 3 years ago

Yes, it is possible. I'll send you a snippet later this weekend when I'm online. Take a look through the examples. There might be one there.

ahopkins commented 3 years ago

Simplest way to do this is with a little bit of monkeypatching.

from sanic_jwt.endpoints import VerifyEndpoint

async def custom_get_response(self, request, *args, **kwargs):
    return response.json({"foo": "bar"})

VerifyEndpoint.get = custom_get_response

app = Sanic("app")
Initialize(app, authenticate=authenticate)
schneider8357 commented 3 years ago

Can you add a decorator to the monkey-patched function, such as @protected() or @scoped(), for instance?