strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓
https://strawberry.rocks
MIT License
4.01k stars 533 forks source link

Support for ABAC compatible permission classes #2346

Open vjrasane opened 2 years ago

vjrasane commented 2 years ago

Currently permission classes seem to be geared towards a RBAC authorization scheme.

The permission classes defined for a resolver are run before the result of the resolver is available, i.e. the source object is None for the initial permission check. The source object is only available when checking permissions for fields of the source object. This makes it difficult to check for the ownership of the initial object, based on username or id for example.

It would be useful if the permission classes could implement permission checks for both before and after the resolver has been run and the result is available.

Upvote & Fund

Fund with Polar

patrick91 commented 2 years ago

hi @vjrasane do you have any idea of how this would look like?

I think this could be probably implemented with extensions and schema directive, but I want to hear your thoughts too, especially since I'm not too familiar with ABAC permissions

DoctorJohn commented 8 months ago

Certainly an interesting request! Extending our permission class to be called before and after resolving a field sounds doable. Do you still need this @vjrasane and would you be interested in working on it?