39 lines
883 B
Go
39 lines
883 B
Go
|
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
|
||
|
|
||
|
}
|