Skip to content

authonly and public directives - safe coding #1068

Answered by rafalp
cancan101 asked this question in Q&A
Discussion options

You must be logged in to vote

When auth-only is the default for your API, then your security should be opt-out.

How to do this?

I would write custom protect_schema utility that would take schema from make_executable_schema and would wrap resolvers on Query and Mutation type with requires_only decorator, but only for fields that don't have @public directive, eg:

def protect_schema(schema):
    protect_schema_type_fields(schema.type_map["Query"])
    protect_schema_type_fields(schema.type_map["Mutation"])


def protect_schema_type_fields(type_fields):
    for field_name, field_type in type_fields.items():
        if not field_type.ast_node:
            field_type.resolve = protect_schema_resolver(field_type.resolve or d…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@cancan101
Comment options

@rafalp
Comment options

@cancan101
Comment options

Answer selected by rafalp
Comment options

You must be logged in to vote
1 reply
@cancan101
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants