git.iko.soy/typeable/oauth2-proxy
on master help sign in
Add static upstream
commit1295f87b33448bafdd67acfef625424d11304a52 authorChristian Groschupp <christian@groschupp.org> dateWed 18 Sep 2019, 22:40 (7 years ago) parent62bf233
3 files changed+13−2
docs/configuration/configuration.md+1−1 main.go+1−1 oauthproxy.go+11
docs/configuration/configuration.md+1−1
@@ -105,7 +105,7 @@ An example [oauth2_proxy.cfg]({{ site.gitweb }}/contrib/oauth2_proxy.cfg.example
105105| `-standard-logging-format` | string | Template for standard log lines | see [Logging Configuration](#logging-configuration) |
106106| `-tls-cert-file` | string | path to certificate file | |
107107| `-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 | |
109109| `-validate-url` | string | Access token validation endpoint | |
110110| `-version` | n/a | print version string | |
111111| `-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() {
3636 flagSet.String("tls-key-file", "", "path to private key file")
3737 flagSet.String("redirect-url", "", "the OAuth Redirect URL. ie: \"https://internalapp.yourcompany.com/oauth2/callback\"")
3838 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")
4040 flagSet.Bool("pass-basic-auth", true, "pass HTTP Basic Auth, X-Forwarded-User and X-Forwarded-Email information to upstream")
4141 flagSet.Bool("pass-user-headers", true, "pass X-Forwarded-User and X-Forwarded-Email information to upstream")
4242 flagSet.String("basic-auth-password", "", "the password to set when passing the HTTP Basic Auth header")
oauthproxy.go+11
@@ -12,6 +12,7 @@ import (
1212 "net/http/httputil"
1313 "net/url"
1414 "regexp"
15+ "strconv"
1516 "strings"
1617 "time"
1718
@@ -207,6 +208,16 @@ func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
207208 proxy := NewWebSocketOrRestReverseProxy(u, opts, auth)
208209 serveMux.Handle(path, proxy)
209210
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+ })
210221 case "file":
211222 if u.Fragment != "" {
212223 path = u.Fragment