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

[QUESTION] - how to make username password work with oauth2 #270

Open
oarkflow opened this issue Dec 20, 2024 · 3 comments
Open

[QUESTION] - how to make username password work with oauth2 #270

oarkflow opened this issue Dec 20, 2024 · 3 comments

Comments

@oarkflow
Copy link

I tried with the example provided in the library. I am able to login with any credentials (username/password), even with wrong credentials.

How to make it work?

@LyricTian
Copy link
Member

Cool, I will try fix this bug, follows this commit: 00133fa9a6e72407ce2286d33994df3e8d967a7e

@oarkflow
Copy link
Author

oarkflow commented Dec 20, 2024

@LyricTian You've added check for username password in POST request of "/login". I was wondering the use of

srv.SetPasswordAuthorizationHandler(func(ctx context.Context, clientID, username, password string) (userID string, err error) {
if username == "test" && password == "test" {
userID = "test"
} else {
err = errors.New("invalid username or password")
}
return
})

Why to include this snippet if we added same logic in POST "/login"

@LyricTian
Copy link
Member

Following your question above , you can see this snippet:

if r.Form.Get("username") == "test" && r.Form.Get("password") == "test" {
store.Set("LoggedInUserID", r.Form.Get("username"))
store.Save()
w.Header().Set("Location", "/auth")
w.WriteHeader(http.StatusFound)
return
} else {
http.Error(w, "Invalid username or password", http.StatusUnauthorized)
return

Fix the scenario where incorrect username and password are input during mock user login.

I tried with the example provided in the library. I am able to login with any credentials (username/password), even with wrong credentials.

How to make it work?

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

No branches or pull requests

2 participants