mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2025-06-29 13:31:01 +02:00
LDAP authentification backend
This commit is contained in:
@ -1,7 +1,36 @@
|
||||
package ldap
|
||||
|
||||
// Options holds web package configuration
|
||||
import (
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
)
|
||||
|
||||
// Options holds package configuration
|
||||
type Options struct {
|
||||
URI string
|
||||
UserDn string
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
Reference in New Issue
Block a user