login-validator: new auth method: http forwarder
This commit is contained in:
parent
c833b64d13
commit
046abdd93c
3 changed files with 41 additions and 2 deletions
26
pkg/login-validator/cmd/auth_fwd.go
Normal file
26
pkg/login-validator/cmd/auth_fwd.go
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in a new issue