git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #63 from freelancer/http-address-scheme

Added scheme parsing to http-address param

commit30e5b636bf79bf40c9b2b7b7859c7cf294c8ba2c authorJehiah Czebotar <jehiah@gmail.com> dateTue 10 Feb 2015, 23:15 (12 years ago) parent601ae6f975c717
2 files changed+25−7
README.md+6−3 main.go+19−4
README.md+6−3
@@ -62,15 +62,18 @@ Usage of google_auth_proxy:
6262 -client-id="": the Google OAuth Client ID: ie: "123456.apps.googleusercontent.com"
6363 -client-secret="": the OAuth Client Secret
6464 -config="": path to config file
65− -cookie-domain="": an optional cookie domain to force cookies to (ie: .yourcompany.com)
65+ -cookie-domain="": an optional cookie domain to force cookies to (ie: .yourcompany.com)*
6666 -cookie-expire=168h0m0s: expire timeframe for cookie
67− -cookie-https-only=false: set HTTPS only cookie
67+ -cookie-httponly=true: set HttpOnly cookie
68+ -cookie-https-only=true: set HTTPS only cookie
6869 -cookie-secret="": the seed string for secure cookies
70+ -display-htpasswd-form=true: display username / password login form if an htpasswd file is provided
6971 -google-apps-domain=: authenticate against the given Google apps domain (may be given multiple times)
7072 -htpasswd-file="": additionally authenticate against a htpasswd file. Entries must be created with "htpasswd -s" for SHA encryption
71− -http-address="127.0.0.1:4180": <addr>:<port> to listen on for HTTP clients
73+ -http-address="127.0.0.1:4180": [http://]<addr>:<port> or unix://<path> to listen on for HTTP clients
7274 -pass-basic-auth=true: pass HTTP Basic Auth, X-Forwarded-User and X-Forwarded-Email information to upstream
7375 -redirect-url="": the OAuth Redirect URL. ie: "https://internalapp.yourcompany.com/oauth2/callback"
76+ -skip-auth-regex=: bypass authentication for requests path's that match (may be given multiple times)
7477 -upstream=: the http url(s) of the upstream endpoint. If multiple, routing is based on path
7578 -version=false: print version string
7679```
main.go+19−4
@@ -6,6 +6,7 @@ import (
66 "log"
77 "net"
88 "net/http"
9+ "net/url"
910 "os"
1011 "strings"
1112 "time"
@@ -24,7 +25,7 @@ func main() {
2425 config := flagSet.String("config", "", "path to config file")
2526 showVersion := flagSet.Bool("version", false, "print version string")
2627
27− flagSet.String("http-address", "127.0.0.1:4180", "<addr>:<port> to listen on for HTTP clients")
28+ flagSet.String("http-address", "127.0.0.1:4180", "[http://]<addr>:<port> or unix://<path> to listen on for HTTP clients")
2829 flagSet.String("redirect-url", "", "the OAuth Redirect URL. ie: \"https://internalapp.yourcompany.com/oauth2/callback\"")
2930 flagSet.Var(&upstreams, "upstream", "the http url(s) of the upstream endpoint. If multiple, routing is based on path")
3031 flagSet.Bool("pass-basic-auth", true, "pass HTTP Basic Auth, X-Forwarded-User and X-Forwarded-Email information to upstream")
@@ -88,11 +89,25 @@ func main() {
8889 }
8990 }
9091
91− listener, err := net.Listen("tcp", opts.HttpAddress)
92+ u, err := url.Parse(opts.HttpAddress)
9293 if err != nil {
93− log.Fatalf("FATAL: listen (%s) failed - %s", opts.HttpAddress, err)
94+ log.Fatalf("FATAL: could not parse %#v: %v", opts.HttpAddress, err)
9495 }
95− log.Printf("listening on %s", opts.HttpAddress)
96+
97+ var networkType string
98+ switch u.Scheme {
99+ case "", "http":
100+ networkType = "tcp"
101+ default:
102+ networkType = u.Scheme
103+ }
104+ listenAddr := strings.TrimPrefix(u.String(), u.Scheme+"://")
105+
106+ listener, err := net.Listen(networkType, listenAddr)
107+ if err != nil {
108+ log.Fatalf("FATAL: listen (%s, %s) failed - %s", networkType, listenAddr, err)
109+ }
110+ log.Printf("listening on %s", listenAddr)
96111
97112 server := &http.Server{Handler: oauthproxy}
98113 err = server.Serve(listener)