git.iko.soy/typeable/oauth2-proxy
on master help sign in
Add static upstream
1295f87Christian Groschupp
docs/configuration/configuration.md+1−1
@@ -105,7 +105,7 @@ An example [oauth2_proxy.cfg]({{ site.gitweb }}/contrib/oauth2_proxy.cfg.example
105| `-standard-logging-format` | string | Template for standard log lines | see [Logging Configuration](#logging-configuration) |
105| `-standard-logging-format` | string | Template for standard log lines | see [Logging Configuration](#logging-configuration) |
106| `-tls-cert-file` | string | path to certificate file | |
106| `-tls-cert-file` | string | path to certificate file | |
107| `-tls-key-file` | string | path to private key file | |
107| `-tls-key-file` | string | path to private key file | |
108−| `-upstream` | string \| list | the http url(s) of the upstream endpoint or `file://` paths for static files. Routing is based on the path | |
108+| `-upstream` | string \| list | the http url(s) of the upstream endpoint, file:// paths for static files or `static://<status_code>` for static response. Routing is based on the path | |
109| `-validate-url` | string | Access token validation endpoint | |
109| `-validate-url` | string | Access token validation endpoint | |
110| `-version` | n/a | print version string | |
110| `-version` | n/a | print version string | |
111| `-whitelist-domain` | string \| list | allowed domains for redirection after authentication. Prefix domain with a `.` to allow subdomains (eg `.example.com`) | |
111| `-whitelist-domain` | string \| list | allowed domains for redirection after authentication. Prefix domain with a `.` to allow subdomains (eg `.example.com`) | |
main.go+1−1
@@ -36,7 +36,7 @@ func main() {
36 flagSet.String("tls-key-file", "", "path to private key file")
36 flagSet.String("tls-key-file", "", "path to private key file")
37 flagSet.String("redirect-url", "", "the OAuth Redirect URL. ie: \"https://internalapp.yourcompany.com/oauth2/callback\"")
37 flagSet.String("redirect-url", "", "the OAuth Redirect URL. ie: \"https://internalapp.yourcompany.com/oauth2/callback\"")
38 flagSet.Bool("set-xauthrequest", false, "set X-Auth-Request-User and X-Auth-Request-Email response headers (useful in Nginx auth_request mode)")
38 flagSet.Bool("set-xauthrequest", false, "set X-Auth-Request-User and X-Auth-Request-Email response headers (useful in Nginx auth_request mode)")
39− flagSet.Var(&upstreams, "upstream", "the http url(s) of the upstream endpoint or file:// paths for static files. Routing is based on the path")
39+ flagSet.Var(&upstreams, "upstream", "the http url(s) of the upstream endpoint, file:// paths for static files or static://<status_code> for static response. Routing is based on the path")
40 flagSet.Bool("pass-basic-auth", true, "pass HTTP Basic Auth, X-Forwarded-User and X-Forwarded-Email information to upstream")
40 flagSet.Bool("pass-basic-auth", true, "pass HTTP Basic Auth, X-Forwarded-User and X-Forwarded-Email information to upstream")
41 flagSet.Bool("pass-user-headers", true, "pass X-Forwarded-User and X-Forwarded-Email information to upstream")
41 flagSet.Bool("pass-user-headers", true, "pass X-Forwarded-User and X-Forwarded-Email information to upstream")
42 flagSet.String("basic-auth-password", "", "the password to set when passing the HTTP Basic Auth header")
42 flagSet.String("basic-auth-password", "", "the password to set when passing the HTTP Basic Auth header")
oauthproxy.go+11
@@ -12,6 +12,7 @@ import (
12 "net/http/httputil"
12 "net/http/httputil"
13 "net/url"
13 "net/url"
14 "regexp"
14 "regexp"
15+ "strconv"
15 "strings"
16 "strings"
16 "time"
17 "time"
17
18
@@ -207,6 +208,16 @@ func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
207 proxy := NewWebSocketOrRestReverseProxy(u, opts, auth)
208 proxy := NewWebSocketOrRestReverseProxy(u, opts, auth)
208 serveMux.Handle(path, proxy)
209 serveMux.Handle(path, proxy)
209
210
211+ case "static":
212+ serveMux.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
213+ responseCode, err := strconv.Atoi(u.Host)
214+ if err != nil {
215+ logger.Printf("unable to convert %q to int, use default \"200\"", u.Host)
216+ responseCode = 200
217+ }
218+ rw.WriteHeader(responseCode)
219+ fmt.Fprintf(rw, "Authenticated")
220+ })
210 case "file":
221 case "file":
211 if u.Fragment != "" {
222 if u.Fragment != "" {
212 path = u.Fragment
223 path = u.Fragment