ahopkins / sanic-jwt

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

Async custom claims #205

Open its-a-feature opened 3 years ago

its-a-feature commented 3 years ago

I'm working on adding custom claims/scopes for another application i'm integrating into my project. From the docs, it looks like I should just do:

class customScope(Claim):
    key = 'foo'

   def setup(self, payload, user):
        return 'bar'

   def verify(self, value):
        return value == 'bar'

However, I need to be able to run setup/verify as async so that I can properly query my database to pull information for the claims. When I make those functions async though, I get an error that they're never awaited. Is there a reason that these can't be async when other sanic-jwt functions involving normal auth/verify/scope/etc can be async?

its-a-feature commented 3 years ago

I ended up doing this with just extend_payload since that allows async, but I think this should be an added feature going forward so that when we add additional claims, we have the ability to verify as well

ahopkins commented 3 years ago

I think you are correct, and I do not think there is necessarily a reason. At least not off the top of my head. I will look into this next week and let you know. Unless, you would like to take a stab at a PR?