跳转至主要内容

Graphql-中间件

Casbin采用官方建议的方式为GraphQL终点提供授权,方法是采用单一的授权来源:https://graphql.org/learn/authorization/ 换句话说,Casbin应该放置在 GraphQL 层和您的业务逻辑之间。

// Casbin授权逻辑位于postRepository内
var postRepository = require('postRepository');

var postType = new GraphQLObjectType({
name: 'Post',
fields: {
body: {
type: GraphQLString,
resolve: (post, args, context, { rootValue }) => {
return postRepository.getBody(context.user, post);
}
}
}
});

支持的 GraphQL 中间件

下面提供了Casbin GraphQL 中间件的完整列表。 我们欢迎来自第三方的中间件,请通知我们以将您的中间件加入列表中:)

中间件GraphQL 实现作者描述
graphql-authzgraphqlCasbin用于graphql-go 的授权中间件
graphql-casbingraphql@esmaeilpour使用 Graphql 和 Casbin 共同实现
gqlgen_casbin_RBAC_examplegqlgen@WenyXu(empty)