You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I would like to ask how to use authenticator to verify username/pass instead of request
Here is the authenticator from the go guardian package
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Println("Executing Auth Middleware")
for k, v := range r.URL.Query() {
log.Printf("%s: %s\n", k, v)
}
user, err := authenticator.Authenticate(r)
What I want to do is to check the user by cheking the username/password passed from frontend form
Like
func SetupGoGuardian(u, p string) (*authentication.User, error) {
// u here is username from form
// p here is password from form
log.Printf("User username %s", u)
cfg := &ldap.Config{
Port: "389",
Host: "ldapadmin.test",
BindDN: "cn=admin,dc=ldapadmin,dc=test",
BindPassword: "root",
BaseDN: "dc=ldapadmin, dc=test",
Filter: "(uid=%s)",
}
authenticator = auth.New()
cache = store.NewFIFO(context.Background(), time.Minute*10)
strategy := ldap.NewCached(cfg, cache)
authenticator.EnableStrategy(ldap.StrategyKey, strategy)
user, err := authenticator.Authenticate(u, p) // this what I want to check my username password,
if err != nil {
return &authentication.User{}, nil
}
return (///////////////////you are now allowed)
Any ideas ?
The text was updated successfully, but these errors were encountered:
@ianrussel
what version you are using ?
unfortunately seems you are using an old version of this package since authenticator only exist in v1.
please describe your use case.
user, err := SetupGoGuardian(username, password)
if err != nil {
http.Error(w, "Authentication failed", http.StatusUnauthorized)
return
}
// Now you can use the authenticated user for authorization or other purposes.
// user.Username and user.Groups can be used to determine access levels.
http.Redirect(w, r, "/dashboard", http.StatusSeeOther)
return
}
// Handle GET request (display login form)
// Render your HTML form here
})
http.ListenAndServe(":8080", nil)
Hi, I would like to ask how to use authenticator to verify username/pass instead of request
Here is the authenticator from the go guardian package
What I want to do is to check the user by cheking the username/password passed from frontend form
Like
Any ideas ?
The text was updated successfully, but these errors were encountered: