set ldap auth

This commit is contained in:
2019-11-27 10:06:24 +01:00
parent 0deab5858d
commit ac4055cf33
8 changed files with 225 additions and 46 deletions

38
auth/auth.go Normal file
View File

@ -0,0 +1,38 @@
package auth
import (
"log"
"github.com/jtblin/go-ldap-client"
)
// LogIn auth the client
func LogIn(username string, password string) (ok bool, user map[string]string) {
ldapclient := &ldap.LDAPClient{
Base: "o=gouv,c=fr",
Host: "ldap.cadoles.com",
Port: 389,
UseSSL: false,
BindDN: "cn=reader,o=gouv,c=fr",
BindPassword: "ohc7kei8lil8Zoesai5chisaiGhu5Yaisai6kaegh9aingai0pae8ohb",
UserFilter: "(uid=%s)",
GroupFilter: "(memberUid=%s)",
Attributes: []string{"uid", "mail"},
}
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
}