1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-02-06 05:33:00 +00:00
ghostream/auth/auth.go
2020-09-22 14:16:52 +02:00

39 lines
677 B
Go

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