kit icon indicating copy to clipboard operation
kit copied to clipboard

Add authorization (AuthZ) support

Open hsluoyz opened this issue 8 years ago • 7 comments

Hi. Currently there's no AuthZ support in kit. Only AuthN exists. Casbin is a popular and powerful authorization (AuthZ) library that supports models like ACL, RBAC, ABAC. I think we can add it here?

hsluoyz avatar Sep 18 '17 06:09 hsluoyz

Hi, I am planning to contribute to open source and this looks good enough. I have recently started on go-programming and would like to contribute to this project. How can i work on adding the AuthZ support in kit?

dreamer-nitj avatar Oct 27 '17 15:10 dreamer-nitj

@dreamer-nitj A good starting point is to get inspiration from looking at existing auth implementations like the JWT one. As soon as you feel comfortable about a possible approach open a PR for review and discussions.

xla avatar Oct 27 '17 15:10 xla

@xla sure. let me look at the possible approaches. Thanks 👍

dreamer-nitj avatar Oct 28 '17 03:10 dreamer-nitj

Hi @xla ,

I am reading the source code and working out the examples currently and in that process i wanted to use the basic authN middleware of go-kit in stringsvc2 example by inserting this code:

var uppercase endpoint.Endpoint
uppercase = makeUppercaseEndpoint(svc)
uppercase = basic.AuthMiddleware("ankit", "ankit", "ankit err")(uppercase)
var count endpoint.Endpoint
count = makeCountEndpoint(svc)
count = basic.AuthMiddleware("ankit", "ankit", "ankit err")(count)

uppercaseHandler := httptransport.NewServer(
	uppercase,
	decodeUppercaseRequest,
	encodeResponse,
)

countHandler := httptransport.NewServer(
	count,
	decodeCountRequest,
	encodeResponse,
)

But when i make a curl request with username:password as "ankit:ankit" , it doesn't work. It says Unauthorized status code. Is there something that i am missing?

Thanks.

dreamer-nitj avatar Oct 29 '17 07:10 dreamer-nitj

I don't understand why is this issue suddenly closed :-(

dreamer-nitj avatar Oct 29 '17 14:10 dreamer-nitj

@dreamer-nitj Not clear to me why it was closed.

The reason your example is not working is that the middleware dependes on a value being present i the context. Usually auth packages have their own way of populating it. In this case it's the common Authorization header which conveniently is handled by transport/http.PopulateRequestContext which needs to be passed as ServerOption to NewServer. The example in the package README shows you how.

xla avatar Oct 30 '17 10:10 xla

@xla Thanks a lot for pointing it out. :)

dreamer-nitj avatar Nov 01 '17 09:11 dreamer-nitj