Gqlgen: Combine with Casbin to add authorization

Created on 27 Nov 2018  路  3Comments  路  Source: 99designs/gqlgen

Feature Request

First of all thanks for the great work. I am planning to generate an API gateway with this library. Is it possible to extend code generation? For example besides schema.graphql I want to define policy.graphql to automatically add guards for the generated endpoints/resolvers.

As an example, auto generating something like in the authentication example

func (r *queryResolver) Hero(ctx context.Context, episode Episode) (Character, error) {
    if user := auth.ForContext(ctx) ; user == nil || !user.IsAdmin {
        return Character{}, fmt.Errorf("Access denied")
    }

     // rest of the function
}

Any ideas are greatly appreciated. I can work on a PR for implementing generic functionality to support this kind of behavior but I think #228 is about this?

Most helpful comment

Ohh missed https://gqlgen.com/reference/directives/ seems like this can help greatly!

All 3 comments

Ohh missed https://gqlgen.com/reference/directives/ seems like this can help greatly!

Directives are made for? @cemremengu closing issue? :)

Here's an example of integrating Casbin into gqlgen: https://github.com/WenyXu/gqlgen_casbin_RBAC_example

Was this page helpful?
0 / 5 - 0 ratings