1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-02-06 10:12:59 +00:00
ghostream/auth/ldap/ldap.go

37 lines
635 B
Go
Raw Normal View History

2020-09-22 11:42:57 +02:00
package ldap
2020-09-22 12:54:12 +02:00
import (
"github.com/go-ldap/ldap/v3"
)
// Options holds package configuration
2020-09-22 11:42:57 +02:00
type Options struct {
URI string
UserDn string
}
2020-09-22 12:54:12 +02:00
// LDAP authentification backend
type LDAP struct {
Cfg Options
}
// Login tries to bind to LDAP
// Returns (true, nil) if success
func (a LDAP) Login(username string, password string) (bool, error) {
// Connect to LDAP server
l, err := ldap.DialURL(a.Cfg.URI)
if err != nil {
return false, err
}
defer l.Close()
// Try to bind as user
err = l.Bind("cn=username,dc=example,dc=com", password)
if err != nil {
return false, err
}
// Login succeeded
return true, nil
}