kit
kit copied to clipboard
auth/casbin readme and example
It's not clear to me how auth/casbin
is meant to be used. I had a look at the test cases but it looks like that's just using hard-coded values. Are we meant to wrap this with our own middleware that injects the subject & object and populates the context with the model & policy or is this just meant to serve as an example implementation?
Would be good to have a readme to add a little more context...
@abeMedia I'm not familar with go-kit, but I guess it could be used like this
uppercaseHandlerWithMid := httptransport.NewServer(
func(ctx context.Context, request interface{}) (response interface{}, err error) {
ctx = context.WithValue(ctx, casbin.CasbinModelContextKey, "/path/to/model")
ctx = context.WithValue(ctx, casbin.CasbinPolicyContextKey, "/path/to/policy")
return casbin.NewEnforcer("alice", "data1", "read")(makeUppercaseEndpoint(svc))(ctx, request)
}, decodeUppercaseRequest, encodeResponse, httptransport.ServerBefore(httptransport.PopulateRequestContext),
)
http.Handle("/uppercasem", uppercaseHandlerWithMid)
http.Handle("/uppercase", uppercaseHandler)
http.Handle("/count", countHandler)
log.Fatal(http.ListenAndServe(":8080", nil))
You could find out model and policy pattern from casbin
This isn't that elegent, request params could be parsed from request