mirror of
https://git.sr.ht/~sircmpwn/tokidoki
synced 2025-12-12 14:17:21 +01:00
Implement configurable auth providers
New providers need to "register" their URL scheme of choice in auth.NewFromURL(). Implements: https://todo.sr.ht/~sircmpwn/tokidoki/1
This commit is contained in:
parent
5f8e94c4a1
commit
071ee7c729
2 changed files with 31 additions and 4 deletions
22
auth/url.go
Normal file
22
auth/url.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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
|
||||
default:
|
||||
return nil, fmt.Errorf("no auth provider found for %s:// URL", u.Scheme)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue