ghostream/auth/auth.go

34 lines
608 B
Go
Raw Normal View History

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