Skip to content

Authenticate username, password passed from frontend #111

@ianrussel

Description

@ianrussel

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions