git.iko.soy/typeable/oauth2-proxy
on master help sign in
adding option to skip provider button sign_in page
commit35547a40cb81c4b3e0ddf38f9d9afb1ba9882580 authorReda Ahdjoudj <reda.ahdjoudj@fairfaxmedia.com.au> dateWed 11 Nov 2015, 11:42 (11 years ago) parent7c241ec
3 files changed+27−18
main.go+1 oauthproxy.go+18−12 options.go+8−6
main.go+1
@@ -36,6 +36,7 @@ func main() {
3636 flagSet.Bool("pass-access-token", false, "pass OAuth access_token to upstream via X-Forwarded-Access-Token header")
3737 flagSet.Bool("pass-host-header", true, "pass the request Host Header to upstream")
3838 flagSet.Var(&skipAuthRegex, "skip-auth-regex", "bypass authentication for requests path's that match (may be given multiple times)")
39+ flagSet.Bool("skip-provider-button", false, "will skip sign-in-page to directly reach the next step: oauth/start")
3940
4041 flagSet.Var(&emailDomains, "email-domain", "authenticate emails with the specified domain (may be given multiple times). Use * to authenticate any email")
4142 flagSet.String("github-org", "", "restrict logins to members of this organisation")
oauthproxy.go+18−12
@@ -43,6 +43,7 @@ type OAuthProxy struct {
4343 DisplayHtpasswdForm bool
4444 serveMux http.Handler
4545 PassBasicAuth bool
46+ SkipProviderButton bool
4647 BasicAuthPassword string
4748 PassAccessToken bool
4849 CookieCipher *cookie.Cipher
@@ -159,17 +160,18 @@ func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
159160 OAuthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix),
160161 AuthOnlyPath: fmt.Sprintf("%s/auth", opts.ProxyPrefix),
161162
162− ProxyPrefix: opts.ProxyPrefix,
163− provider: opts.provider,
164− serveMux: serveMux,
165− redirectURL: redirectURL,
166− skipAuthRegex: opts.SkipAuthRegex,
167− compiledRegex: opts.CompiledRegex,
168− PassBasicAuth: opts.PassBasicAuth,
169− BasicAuthPassword: opts.BasicAuthPassword,
170− PassAccessToken: opts.PassAccessToken,
171− CookieCipher: cipher,
172− templates: loadTemplates(opts.CustomTemplatesDir),
163+ ProxyPrefix: opts.ProxyPrefix,
164+ provider: opts.provider,
165+ serveMux: serveMux,
166+ redirectURL: redirectURL,
167+ skipAuthRegex: opts.SkipAuthRegex,
168+ compiledRegex: opts.CompiledRegex,
169+ PassBasicAuth: opts.PassBasicAuth,
170+ BasicAuthPassword: opts.BasicAuthPassword,
171+ PassAccessToken: opts.PassAccessToken,
172+ SkipProviderButton: opts.SkipProviderButton,
173+ CookieCipher: cipher,
174+ templates: loadTemplates(opts.CustomTemplatesDir),
173175 }
174176}
175177
@@ -484,7 +486,11 @@ func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
484486 p.ErrorPage(rw, http.StatusInternalServerError,
485487 "Internal Error", "Internal Error")
486488 } else if status == http.StatusForbidden {
487− p.SignInPage(rw, req, http.StatusForbidden)
489+ if p.SkipProviderButton {
490+ p.OAuthStart(rw, req)
491+ } else {
492+ p.SignInPage(rw, req, http.StatusForbidden)
493+ }
488494 } else {
489495 p.serveMux.ServeHTTP(rw, req)
490496 }
options.go+8−6
@@ -41,12 +41,13 @@ type Options struct {
4141 CookieSecure bool `flag:"cookie-secure" cfg:"cookie_secure"`
4242 CookieHttpOnly bool `flag:"cookie-httponly" cfg:"cookie_httponly"`
4343
44− Upstreams []string `flag:"upstream" cfg:"upstreams"`
45− SkipAuthRegex []string `flag:"skip-auth-regex" cfg:"skip_auth_regex"`
46− PassBasicAuth bool `flag:"pass-basic-auth" cfg:"pass_basic_auth"`
47− BasicAuthPassword string `flag:"basic-auth-password" cfg:"basic_auth_password"`
48− PassAccessToken bool `flag:"pass-access-token" cfg:"pass_access_token"`
49− PassHostHeader bool `flag:"pass-host-header" cfg:"pass_host_header"`
44+ Upstreams []string `flag:"upstream" cfg:"upstreams"`
45+ SkipAuthRegex []string `flag:"skip-auth-regex" cfg:"skip_auth_regex"`
46+ PassBasicAuth bool `flag:"pass-basic-auth" cfg:"pass_basic_auth"`
47+ BasicAuthPassword string `flag:"basic-auth-password" cfg:"basic_auth_password"`
48+ PassAccessToken bool `flag:"pass-access-token" cfg:"pass_access_token"`
49+ PassHostHeader bool `flag:"pass-host-header" cfg:"pass_host_header"`
50+ SkipProviderButton bool `flag:"skip-provider-button" cfg:"skip_provider_button"`
5051
5152 // These options allow for other providers besides Google, with
5253 // potential overrides.
@@ -81,6 +82,7 @@ func NewOptions() *Options {
8182 PassBasicAuth: true,
8283 PassAccessToken: false,
8384 PassHostHeader: true,
85+ SkipProviderButton: false,
8486 ApprovalPrompt: "force",
8587 RequestLogging: true,
8688 }