You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-06-15 00:15:00 +02:00
Added scheme parsing to http-address param
Can now listen for HTTP clients on unix sockets (and any other Go-supported stream oriented network - see golang.org/pkg/net/#Listen). Default behaviour is unchanged, any http-address without a scheme is given the default of tcp. Amended the README so that the usage output is up to date.
This commit is contained in:
23
main.go
23
main.go
@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
@ -24,7 +25,7 @@ func main() {
|
||||
config := flagSet.String("config", "", "path to config file")
|
||||
showVersion := flagSet.Bool("version", false, "print version string")
|
||||
|
||||
flagSet.String("http-address", "127.0.0.1:4180", "<addr>:<port> to listen on for HTTP clients")
|
||||
flagSet.String("http-address", "127.0.0.1:4180", "[http://]<addr>:<port> or unix://<path> to listen on for HTTP clients")
|
||||
flagSet.String("redirect-url", "", "the OAuth Redirect URL. ie: \"https://internalapp.yourcompany.com/oauth2/callback\"")
|
||||
flagSet.Var(&upstreams, "upstream", "the http url(s) of the upstream endpoint. If multiple, routing is based on path")
|
||||
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() {
|
||||
}
|
||||
}
|
||||
|
||||
listener, err := net.Listen("tcp", opts.HttpAddress)
|
||||
u, err := url.Parse(opts.HttpAddress)
|
||||
if err != nil {
|
||||
log.Fatalf("FATAL: listen (%s) failed - %s", opts.HttpAddress, err)
|
||||
log.Fatalf("FATAL: could not parse %#v: %v", opts.HttpAddress, err)
|
||||
}
|
||||
log.Printf("listening on %s", opts.HttpAddress)
|
||||
|
||||
var networkType string
|
||||
switch u.Scheme {
|
||||
case "", "http":
|
||||
networkType = "tcp"
|
||||
default:
|
||||
networkType = u.Scheme
|
||||
}
|
||||
listenAddr := strings.TrimPrefix(u.String(), u.Scheme+"://")
|
||||
|
||||
listener, err := net.Listen(networkType, listenAddr)
|
||||
if err != nil {
|
||||
log.Fatalf("FATAL: listen (%s, %s) failed - %s", networkType, listenAddr, err)
|
||||
}
|
||||
log.Printf("listening on %s", listenAddr)
|
||||
|
||||
server := &http.Server{Handler: oauthproxy}
|
||||
err = server.Serve(listener)
|
||||
|
Reference in New Issue
Block a user