login-validator: new auth method: http forwarder

This commit is contained in:
nemunaire 2020-02-21 01:05:53 +01:00
commit 046abdd93c
3 changed files with 41 additions and 2 deletions

View file

@ -0,0 +1,26 @@
package main
import (
"net/http"
"net/url"
)
type FWDAuth struct {
URI *url.URL
}
func (f FWDAuth) checkAuth(username, password string) (res bool, err error) {
if r, err := http.NewRequest("GET", f.URI.String(), nil); err != nil {
return false, err
} else {
r.SetBasicAuth(username, password)
if resp, err := http.DefaultClient.Do(r); err != nil {
return false, err
} else {
resp.Body.Close()
return resp.StatusCode < 400, err
}
}
}