Skip to content
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

auth/casbin readme and example #972

Open
abemedia opened this issue Apr 4, 2020 · 1 comment
Open

auth/casbin readme and example #972

abemedia opened this issue Apr 4, 2020 · 1 comment

Comments

@abemedia
Copy link

abemedia commented Apr 4, 2020

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 abemedia changed the title auth/casbin readme/example auth/casbin readme and example Apr 4, 2020
@kilosonc
Copy link

kilosonc commented Mar 29, 2021

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants