git.iko.soy/typeable/oauth2-proxy
on master help sign in
Allow hiding custom login UI even if an htpasswd file is provided.
commit69804e588a972cdf8fb774fc088cf8e442ba43d3 authordrew <drew@drewolson.org> dateTue 9 Dec 2014, 14:38 (12 years ago) parent5199e00
5 files changed+27−19
main.go+2 oauthproxy.go+17−12 options.go+6−4 templates.go+2−2 templates_test.go−1
main.go+2
@@ -33,6 +33,7 @@ func main() {
3333 flagSet.String("client-secret", "", "the OAuth Client Secret")
3434 flagSet.String("authenticated-emails-file", "", "authenticate against emails via file (one per line)")
3535 flagSet.String("htpasswd-file", "", "additionally authenticate against a htpasswd file. Entries must be created with \"htpasswd -s\" for SHA encryption")
36+ flagSet.Bool("display-htpasswd-form", true, "display username / password login form if an htpasswd file is provided")
3637
3738 flagSet.String("cookie-secret", "", "the seed string for secure cookies")
3839 flagSet.String("cookie-domain", "", "an optional cookie domain to force cookies to (ie: .yourcompany.com)*")
@@ -78,6 +79,7 @@ func main() {
7879 if opts.HtpasswdFile != "" {
7980 log.Printf("using htpasswd file %s", opts.HtpasswdFile)
8081 oauthproxy.HtpasswdFile, err = NewHtpasswdFromFile(opts.HtpasswdFile)
82+ oauthproxy.DisplayHtpasswdForm = opts.DisplayHtpasswdForm
8183 if err != nil {
8284 log.Fatalf("FATAL: unable to open %s %s", opts.HtpasswdFile, err)
8385 }
oauthproxy.go+17−12
@@ -29,16 +29,17 @@ type OauthProxy struct {
2929 CookieExpire time.Duration
3030 Validator func(string) bool
3131
32− redirectUrl *url.URL // the url to receive requests at
33− oauthRedemptionUrl *url.URL // endpoint to redeem the code
34− oauthLoginUrl *url.URL // to redirect the user to
35− oauthScope string
36− clientID string
37− clientSecret string
38− SignInMessage string
39− HtpasswdFile *HtpasswdFile
40− serveMux *http.ServeMux
41− PassBasicAuth bool
32+ redirectUrl *url.URL // the url to receive requests at
33+ oauthRedemptionUrl *url.URL // endpoint to redeem the code
34+ oauthLoginUrl *url.URL // to redirect the user to
35+ oauthScope string
36+ clientID string
37+ clientSecret string
38+ SignInMessage string
39+ HtpasswdFile *HtpasswdFile
40+ DisplayHtpasswdForm bool
41+ serveMux *http.ServeMux
42+ PassBasicAuth bool
4243}
4344
4445func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
@@ -114,6 +115,10 @@ func apiRequest(req *http.Request) (*simplejson.Json, error) {
114115 return data, nil
115116}
116117
118+func (p *OauthProxy) displayCustomLoginForm() bool {
119+ return p.HtpasswdFile != nil && p.DisplayHtpasswdForm
120+}
121+
117122func (p *OauthProxy) redeemCode(code string) (string, string, error) {
118123 if code == "" {
119124 return "", "", errors.New("missing code")
@@ -232,12 +237,12 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
232237
233238 t := struct {
234239 SignInMessage string
235− Htpasswd bool
240+ CustomLogin bool
236241 Redirect string
237242 Version string
238243 }{
239244 SignInMessage: p.SignInMessage,
240− Htpasswd: p.HtpasswdFile != nil,
245+ CustomLogin: p.displayCustomLoginForm(),
241246 Redirect: req.URL.RequestURI(),
242247 Version: VERSION,
243248 }
options.go+6−4
@@ -15,6 +15,7 @@ type Options struct {
1515 ClientSecret string `flag:"client-secret" cfg:"client_secret" env:"GOOGLE_AUTH_PROXY_CLIENT_SECRET"`
1616 PassBasicAuth bool `flag:"pass-basic-auth" cfg:"pass_basic_auth"`
1717 HtpasswdFile string `flag:"htpasswd-file" cfg:"htpasswd_file"`
18+ DisplayHtpasswdForm bool `flag:"display-htpasswd-form" cfg:"display_htpasswd_form"`
1819 CookieSecret string `flag:"cookie-secret" cfg:"cookie_secret" env:"GOOGLE_AUTH_PROXY_COOKIE_SECRET"`
1920 CookieDomain string `flag:"cookie-domain" cfg:"cookie_domain" env:"GOOGLE_AUTH_PROXY_COOKIE_DOMAIN"`
2021 CookieExpire time.Duration `flag:"cookie-expire" cfg:"cookie_expire" env:"GOOGLE_AUTH_PROXY_COOKIE_EXPIRE"`
@@ -30,10 +31,11 @@ type Options struct {
3031
3132func NewOptions() *Options {
3233 return &Options{
33− HttpAddress: "127.0.0.1:4180",
34− CookieHttpsOnly: true,
35− PassBasicAuth: true,
36− CookieExpire: time.Duration(168) * time.Hour,
34+ HttpAddress: "127.0.0.1:4180",
35+ DisplayHtpasswdForm: true,
36+ CookieHttpsOnly: true,
37+ PassBasicAuth: true,
38+ CookieExpire: time.Duration(168) * time.Hour,
3739 }
3840}
3941
templates.go+2−2
@@ -105,8 +105,8 @@ func getTemplates() *template.Template {
105105 <button type="submit" class="btn">Sign in with a Google Account</button><br/>
106106 </form>
107107 </div>
108−
109− {{ if .Htpasswd }}
108+
109+ {{ if .CustomLogin }}
110110 <div class="signin">
111111 <form method="POST" action="/oauth2/sign_in">
112112 <input type="hidden" name="rd" value="{{.Redirect}}">
templates_test.go−1
@@ -8,5 +8,4 @@ import (
88func TestTemplatesCompile(t *testing.T) {
99 templates := getTemplates()
1010 assert.NotEqual(t, templates, nil)
11−
1211}