2022-02-22 10:44:37 +00:00
|
|
|
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
|
2022-09-10 18:13:20 +01:00
|
|
|
case "pam":
|
|
|
|
return NewPAM()
|
2024-02-05 16:23:11 +00:00
|
|
|
case "file":
|
|
|
|
path := u.Path
|
|
|
|
if u.Host != "" {
|
|
|
|
path = u.Host + path
|
|
|
|
}
|
|
|
|
return NewHtpasswd(path)
|
2024-02-01 13:21:43 +00:00
|
|
|
case "null":
|
|
|
|
return NewNull()
|
2022-02-22 10:44:37 +00:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("no auth provider found for %s:// URL", u.Scheme)
|
|
|
|
}
|
|
|
|
}
|