git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #161 from rahdjoudj/master

adding option to skip provider button sign_in page

commit168cff9d4b4a6453613be376b0d487ed6f4f4556 authorJehiah Czebotar <jehiah@gmail.com> dateSat 18 Jun 2016, 23:31 (10 years ago) parentfe143ca35547a4
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("azure-tenant", "common", "go to a tenant-specific or common (tenant-independent) endpoint.")
oauthproxy.go+18−12
@@ -59,6 +59,7 @@ type OAuthProxy struct {
5959 DisplayHtpasswdForm bool
6060 serveMux http.Handler
6161 PassBasicAuth bool
62+ SkipProviderButton bool
6263 BasicAuthPassword string
6364 PassAccessToken bool
6465 CookieCipher *cookie.Cipher
@@ -186,17 +187,18 @@ func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
186187 OAuthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix),
187188 AuthOnlyPath: fmt.Sprintf("%s/auth", opts.ProxyPrefix),
188189
189− ProxyPrefix: opts.ProxyPrefix,
190− provider: opts.provider,
191− serveMux: serveMux,
192− redirectURL: redirectURL,
193− skipAuthRegex: opts.SkipAuthRegex,
194− compiledRegex: opts.CompiledRegex,
195− PassBasicAuth: opts.PassBasicAuth,
196− BasicAuthPassword: opts.BasicAuthPassword,
197− PassAccessToken: opts.PassAccessToken,
198− CookieCipher: cipher,
199− templates: loadTemplates(opts.CustomTemplatesDir),
190+ ProxyPrefix: opts.ProxyPrefix,
191+ provider: opts.provider,
192+ serveMux: serveMux,
193+ redirectURL: redirectURL,
194+ skipAuthRegex: opts.SkipAuthRegex,
195+ compiledRegex: opts.CompiledRegex,
196+ PassBasicAuth: opts.PassBasicAuth,
197+ BasicAuthPassword: opts.BasicAuthPassword,
198+ PassAccessToken: opts.PassAccessToken,
199+ SkipProviderButton: opts.SkipProviderButton,
200+ CookieCipher: cipher,
201+ templates: loadTemplates(opts.CustomTemplatesDir),
200202 }
201203}
202204
@@ -511,7 +513,11 @@ func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
511513 p.ErrorPage(rw, http.StatusInternalServerError,
512514 "Internal Error", "Internal Error")
513515 } else if status == http.StatusForbidden {
514− p.SignInPage(rw, req, http.StatusForbidden)
516+ if p.SkipProviderButton {
517+ p.OAuthStart(rw, req)
518+ } else {
519+ p.SignInPage(rw, req, http.StatusForbidden)
520+ }
515521 } else {
516522 p.serveMux.ServeHTTP(rw, req)
517523 }
options.go+8−6
@@ -44,12 +44,13 @@ type Options struct {
4444 CookieSecure bool `flag:"cookie-secure" cfg:"cookie_secure"`
4545 CookieHttpOnly bool `flag:"cookie-httponly" cfg:"cookie_httponly"`
4646
47− Upstreams []string `flag:"upstream" cfg:"upstreams"`
48− SkipAuthRegex []string `flag:"skip-auth-regex" cfg:"skip_auth_regex"`
49− PassBasicAuth bool `flag:"pass-basic-auth" cfg:"pass_basic_auth"`
50− BasicAuthPassword string `flag:"basic-auth-password" cfg:"basic_auth_password"`
51− PassAccessToken bool `flag:"pass-access-token" cfg:"pass_access_token"`
52− PassHostHeader bool `flag:"pass-host-header" cfg:"pass_host_header"`
47+ Upstreams []string `flag:"upstream" cfg:"upstreams"`
48+ SkipAuthRegex []string `flag:"skip-auth-regex" cfg:"skip_auth_regex"`
49+ PassBasicAuth bool `flag:"pass-basic-auth" cfg:"pass_basic_auth"`
50+ BasicAuthPassword string `flag:"basic-auth-password" cfg:"basic_auth_password"`
51+ PassAccessToken bool `flag:"pass-access-token" cfg:"pass_access_token"`
52+ PassHostHeader bool `flag:"pass-host-header" cfg:"pass_host_header"`
53+ SkipProviderButton bool `flag:"skip-provider-button" cfg:"skip_provider_button"`
5354
5455 // These options allow for other providers besides Google, with
5556 // potential overrides.
@@ -93,6 +94,7 @@ func NewOptions() *Options {
9394 PassBasicAuth: true,
9495 PassAccessToken: false,
9596 PassHostHeader: true,
97+ SkipProviderButton: false,
9698 ApprovalPrompt: "force",
9799 RequestLogging: true,
98100 }