login-validator: now it's not a simple GET, use custom json form
This commit is contained in:
parent
4ce6f09a8d
commit
0aa8a1e9ff
1 changed files with 16 additions and 9 deletions
|
@ -1,6 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
@ -9,18 +11,23 @@ type FWDAuth struct {
|
||||||
URI *url.URL
|
URI *url.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type loginForm struct {
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
}
|
||||||
|
|
||||||
func (f FWDAuth) checkAuth(username, password string) (res bool, err error) {
|
func (f FWDAuth) checkAuth(username, password string) (res bool, err error) {
|
||||||
if r, err := http.NewRequest("GET", f.URI.String(), nil); err != nil {
|
lf := loginForm{username, password}
|
||||||
|
j, err := json.Marshal(lf)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
} else if r, err := http.NewRequest("POST", f.URI.String(), bytes.NewReader(j)); err != nil {
|
||||||
|
return false, err
|
||||||
|
} else if resp, err := http.DefaultClient.Do(r); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
} else {
|
} else {
|
||||||
r.SetBasicAuth(username, password)
|
resp.Body.Close()
|
||||||
|
|
||||||
if resp, err := http.DefaultClient.Do(r); err != nil {
|
return resp.StatusCode < 400, err
|
||||||
return false, err
|
|
||||||
} else {
|
|
||||||
resp.Body.Close()
|
|
||||||
|
|
||||||
return resp.StatusCode < 400, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue