kit
kit copied to clipboard
Add authorization (AuthZ) support
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?
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 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 sure. let me look at the possible approaches. Thanks 👍
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.
I don't understand why is this issue suddenly closed :-(
@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 Thanks a lot for pointing it out. :)