tokidoki/auth/url.go
Conrad Hoffmann a87520cb0f Add htpasswd-style static file auth module
Can be used via `-auth.url=file://`. Only supports bcrypt password
hashes ($2y). Use e.g. `htpasswd -c -BC 14 <filename> <user>` to create
a file. Documentation forthcoming.
2024-02-05 17:23:11 +01:00

33 lines
600 B
Go

package auth
import (
"fmt"
"net/url"
)
func NewFromURL(authURL string) (AuthProvider, error) {
u, err := url.Parse(authURL)
if err != nil {
return nil, fmt.Errorf("error parsing auth URL: %s", err.Error())
}
switch u.Scheme {
case "imap":
return NewIMAP(u.Host, false), nil
case "imaps":
return NewIMAP(u.Host, true), nil
case "pam":
return NewPAM()
case "file":
path := u.Path
if u.Host != "" {
path = u.Host + path
}
return NewHtpasswd(path)
case "null":
return NewNull()
default:
return nil, fmt.Errorf("no auth provider found for %s:// URL", u.Scheme)
}
}