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: basic auth without keeping a list of accounts #3562

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stefanbildl
Copy link

@stefanbildl stefanbildl commented Apr 9, 2023

Hi,
while using gin I often wanted to use basic authentication that does not require me to save all available accounts to a map (Currently it is handled that way).

I wanted to be able to pass a username and password validator that directly "plugs into" gin.

Example:

I have a function that checks if a user and password combination is right.

func isValidUser(username string, password string) (valid bool) {
    // e.g. LDAP authentication is done here 
    // if user and password match, return true
}

It does not include any basic authentication specific code. Realm and authentication headers are hidden from the user of the library.
This function (of type UsernamePasswordValidator) can now be converted to a gin basic authentication middleware like so:

middleware := BasicAuthForRealmWithValidator(isValidUser, "")

I added tests and refactored the current code so that it integrates seamlessly with this new behavior.

I hope you like it.

Thank you for this great library. It is a joy to use.

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.

None yet

1 participant