Allow hiding custom login UI even if an htpasswd file is provided.

This commit is contained in:
drew
2014-12-09 14:38:57 -06:00
parent 5199e0028b
commit 69804e588a
5 changed files with 27 additions and 19 deletions
+17 -12
View File
@@ -29,16 +29,17 @@ type OauthProxy struct {
CookieExpire time.Duration
Validator func(string) bool
redirectUrl *url.URL // the url to receive requests at
oauthRedemptionUrl *url.URL // endpoint to redeem the code
oauthLoginUrl *url.URL // to redirect the user to
oauthScope string
clientID string
clientSecret string
SignInMessage string
HtpasswdFile *HtpasswdFile
serveMux *http.ServeMux
PassBasicAuth bool
redirectUrl *url.URL // the url to receive requests at
oauthRedemptionUrl *url.URL // endpoint to redeem the code
oauthLoginUrl *url.URL // to redirect the user to
oauthScope string
clientID string
clientSecret string
SignInMessage string
HtpasswdFile *HtpasswdFile
DisplayHtpasswdForm bool
serveMux *http.ServeMux
PassBasicAuth bool
}
func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
@@ -114,6 +115,10 @@ func apiRequest(req *http.Request) (*simplejson.Json, error) {
return data, nil
}
func (p *OauthProxy) displayCustomLoginForm() bool {
return p.HtpasswdFile != nil && p.DisplayHtpasswdForm
}
func (p *OauthProxy) redeemCode(code string) (string, string, error) {
if code == "" {
return "", "", errors.New("missing code")
@@ -232,12 +237,12 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
t := struct {
SignInMessage string
Htpasswd bool
CustomLogin bool
Redirect string
Version string
}{
SignInMessage: p.SignInMessage,
Htpasswd: p.HtpasswdFile != nil,
CustomLogin: p.displayCustomLoginForm(),
Redirect: req.URL.RequestURI(),
Version: VERSION,
}