1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-03-15 01:07:29 +00:00
ghostream/auth/auth.go

39 lines
677 B
Go
Raw Normal View History

2020-09-22 11:42:57 +02:00
package auth
import (
2020-09-22 12:54:12 +02:00
"errors"
2020-09-22 11:42:57 +02:00
"gitlab.crans.org/nounous/ghostream/auth/ldap"
)
2020-09-22 12:54:12 +02:00
// Options holds package configuration
2020-09-22 11:42:57 +02:00
type Options struct {
Backend string
LDAP ldap.Options
}
2020-09-22 12:54:12 +02:00
// Backend to log user in
type Backend interface {
Login(string, string) (bool, error)
Close()
2020-09-22 12:54:12 +02:00
}
// New initialize authentification backend
func New(cfg *Options) (Backend, error) {
var backend Backend
var err error
2020-09-22 12:54:12 +02:00
if cfg.Backend == "LDAP" {
backend, err = ldap.NewLDAP(&cfg.LDAP)
if err != nil {
return nil, err
}
2020-09-22 12:54:12 +02:00
} else {
// Package is misconfigured
return nil, errors.New("Authentification backend not found")
}
// Init and return backend
return backend, nil
}