-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How do you recommend enforcing authorization? #186
Comments
Hi @hoffrocket ! This is a "hot" subject in the graphene community (here for example) and no "official" answer have been defined yet, so the framework is not opiniated for now. I suggest you to follow the official graphql suggestion to implement the authorization logic on the business layer. And for a more concrete answer, I have a suggestion from Dan Palmer for you :
|
Thanks @Nabellaleen Our goals:
We had been solving these concerns by being using class OurNode(SQLAlchemyObjectType):
class Meta:
only_fields = ("name", "created_at",...)
@self_or_staff_required
def resolve_name(self, info):
return self.name
@staff_required
def resolve_created_at(self, info):
return self.created_at I've been experimenting with the concept above and it's pretty similar to what @dfee suggests here graphql-python/graphene-django#79 (comment) It seems to work, and I wonder if we can get some consensus around an approach that could be pushed upstream and be generally useful. One fundamental challenge to overcome in this community is that graphene-django is basically a superset and fork of graphene-sqlalchemy. |
This is somewhat old but still open. Has there been any additional development to support this in graphene-sqlalchemy, or are there authorization patterns the community has settled on as workable? |
We have an example of doing authorization with sqlalchemy-oso and graphene in this blog post. This adheres to the "do it at the business layer" principle that the docs recommend, and might be helpful for folks who don't want to insert a ton of additional code into their graphql api. We'd love to get feedback from people on how we could improve this! |
Thank you! |
Hello,
I'd like to systematically enforce authorization for nodes and individual fields within the nodes.
Conceptually something like this might work:
node_authorizer(model_instance)
would get called whenever a new Node of that type is created. Only fields in the field_auth dict would be exposed in node, and then the associated function would be called likeresolve_authorizer(model_instance, field_name)
Any opinions on the best way to achieve this?
The text was updated successfully, but these errors were encountered: