package auth import ( "cadoles/foodoles/config" "log" "github.com/jtblin/go-ldap-client" "github.com/pkg/errors" ) // LogIn auth the client func LogIn(username string, password string) (ok bool, user map[string]string) { var configFile = "server.conf" var conf *config.Config var conferr error conf, conferr = config.NewFromFile(configFile) if conferr != nil { panic(errors.Wrapf(conferr, "error while loading config file '%s'", configFile)) } ldapclient := &ldap.LDAPClient{ Base: conf.LDAP.Base, Host: conf.LDAP.Host, Port: conf.LDAP.Port, UseSSL: false, BindDN: conf.LDAP.BindDN, BindPassword: conf.LDAP.BindPassword, UserFilter: conf.LDAP.UserFilter, GroupFilter: "(memberUid=%s)", Attributes: conf.LDAP.Attributes, } log.Print(ldapclient) defer ldapclient.Close() ok, user, err := ldapclient.Authenticate(username, password) if err != nil { log.Printf("Error authenticating user %s: %+v", "username", err) return } if !ok { log.Printf("Authenticating failed for user %s", "username") return } log.Printf("User %s authentificated", username) return ok, user }