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

feat(casbin): let the caller decide the method of user identification #41

Merged
merged 3 commits into from
Feb 10, 2021

Conversation

gdemarcsek
Copy link
Contributor

This feature lets the caller decide the strategy of identifying the user. The default options remains to be using the username from HTTP basic auth, so it is a non-breaking change that offers more flexibility to users.

@codecov
Copy link

codecov bot commented Nov 16, 2020

Codecov Report

Merging #41 (9af1797) into master (978e622) will increase coverage by 0.60%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #41      +/-   ##
==========================================
+ Coverage   50.00%   50.60%   +0.60%     
==========================================
  Files           5        5              
  Lines         326      330       +4     
==========================================
+ Hits          163      167       +4     
  Misses        153      153              
  Partials       10       10              
Impacted Files Coverage Δ
casbin/casbin.go 83.33% <100.00%> (+3.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 978e622...e4d7262. Read the comment docs.

@lammel
Copy link
Contributor

lammel commented Dec 12, 2020

Very nice @gdemarcsek!

Would you mind adding a test for the proposed UserGetter?
Also an usage example in the cookbook in labstack/echox with a usage example will be very helpful to others. Maybe you could add a PR there too.

casbin/casbin.go Outdated
@@ -109,7 +116,7 @@ func MiddlewareWithConfig(config Config) echo.MiddlewareFunc {
// GetUserName gets the user name from the request.
// Currently, only HTTP basic authentication is supported
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't forget to update this comment (thanks to you this method supports "to infinity and beyond!" 😉)

casbin/casbin.go Outdated
@@ -109,7 +116,7 @@ func MiddlewareWithConfig(config Config) echo.MiddlewareFunc {
// GetUserName gets the user name from the request.
// Currently, only HTTP basic authentication is supported
func (a *Config) GetUserName(c echo.Context) string {
username, _, _ := c.Request().BasicAuth()
username, _ := a.UserGetter(c)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if ignoring the error it's OK. I know that our current implementation do that, but if this could be an opportunity to improve this code. Could you please change the signature of GetUserName to return also an error and check it on CheckPermission?

@gdemarcsek
Copy link
Contributor Author

@pafuent Thanks, sorry, I completely forgot about this, will try to get back to this later this week.

@pafuent
Copy link

pafuent commented Jan 20, 2021

@gdemarcsek Sure, no problem

@gdemarcsek gdemarcsek requested a review from pafuent January 25, 2021 19:15
Copy link

@pafuent pafuent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lammel lammel merged commit 7944b61 into labstack:master Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants