Skip to content

Commit

Permalink
Make proxy listen address configurable
Browse files Browse the repository at this point in the history
The auth callback address must be fixed, so we can allow the
redirect_uri at the identity provider.
  • Loading branch information
mfrister committed Jul 17, 2018
1 parent 269ac3f commit a1bc14a
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"flag"
"fmt"
"log"
"net/http"
Expand All @@ -15,30 +16,38 @@ import (
)

func main() {
proxyAddr := "127.0.0.1:8124"
proxyAddr := flag.String("addr", "127.0.0.1:8124",
"Listen on this address for reverse proxy requests")

if len(os.Args) != 2 {
flag.Usage = func() {
fmt.Fprintf(os.Stderr,
"Usage: %s UPSTREAM_URL\n"+
"Usage: %s [flags] UPSTREAM_URL\n"+
"Example: %s https://proxy-dev.example.com\n\n"+
"Note: The oauth2_proxy running at UPSTREAM_URL must be configured with a\n"+
" special redirect URL for this development proxy.\n",
" special redirect URL for this development proxy.\n\n",
os.Args[0], os.Args[0])
flag.PrintDefaults()
}

flag.Parse()

if len(flag.Args()) != 1 {
flag.Usage()
os.Exit(1)
}

upstreamURL, err := url.Parse(os.Args[1])
upstreamURL, err := url.Parse(flag.Args()[0])
if err != nil {
log.Fatalf("Failed to parse target URL: %v", err)
}

authCompleteNotice := fmt.Sprintf("Authentication complete. You can now use the proxy.\n\n"+
"Proxy URL: http://%s\n"+
"Upstream: %s\n\n", proxyAddr, upstreamURL)
"Upstream: %s\n\n", *proxyAddr, upstreamURL)

authCookie := authenticate(upstreamURL, authCompleteNotice)

go runProxy(proxyAddr, upstreamURL, authCookie)
go runProxy(*proxyAddr, upstreamURL, authCookie)

log.Printf("The proxy will automatically terminate in 12 hours (reauthentication required)")

Expand Down

0 comments on commit a1bc14a

Please sign in to comment.