13 "github.com/justinas/alice"
14 "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/options"
15 "github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
16 "github.com/oauth2-proxy/oauth2-proxy/pkg/middleware"
17 "github.com/oauth2-proxy/oauth2-proxy/pkg/validation"
21 logger.SetFlags(logger.Lshortfile)
22 flagSet := options.NewFlagSet()
24 config := flagSet.String("config", "", "path to config file")
25 showVersion := flagSet.Bool("version", false, "print version string")
27 flagSet.Parse(os.Args[1:])
30 fmt.Printf("oauth2-proxy %s (built with %s)\n", VERSION, runtime.Version())
34 opts := options.NewOptions()
35 err := options.Load(*config, flagSet, opts)
37 logger.Printf("ERROR: Failed to load config: %v", err)
41 err = validation.Validate(opts)
43 logger.Printf("%s", err)
47 validator := NewValidator(opts.EmailDomains, opts.AuthenticatedEmailsFile)
48 oauthproxy := NewOAuthProxy(opts, validator)
50 if len(opts.Banner) >= 1 {
51 if opts.Banner == "-" {
52 oauthproxy.SignInMessage = ""
54 oauthproxy.SignInMessage = opts.Banner
56 } else if len(opts.EmailDomains) != 0 && opts.AuthenticatedEmailsFile == "" {
57 if len(opts.EmailDomains) > 1 {
58 oauthproxy.SignInMessage = fmt.Sprintf("Authenticate using one of the following domains: %v", strings.Join(opts.EmailDomains, ", "))
59 } else if opts.EmailDomains[0] != "*" {
60 oauthproxy.SignInMessage = fmt.Sprintf("Authenticate using %v", opts.EmailDomains[0])
64 if opts.HtpasswdFile != "" {
65 logger.Printf("using htpasswd file %s", opts.HtpasswdFile)
66 oauthproxy.HtpasswdFile, err = NewHtpasswdFromFile(opts.HtpasswdFile)
67 oauthproxy.DisplayHtpasswdForm = opts.DisplayHtpasswdForm
69 logger.Fatalf("FATAL: unable to open %s %s", opts.HtpasswdFile, err)
73 rand.Seed(time.Now().UnixNano())
78 chain = chain.Append(newRedirectToHTTPS(opts))
81 healthCheckPaths := []string{opts.PingPath}
82 healthCheckUserAgents := []string{opts.PingUserAgent}
83 if opts.GCPHealthChecks {
84 healthCheckPaths = append(healthCheckPaths, "/liveness_check", "/readiness_check")
85 healthCheckUserAgents = append(healthCheckUserAgents, "GoogleHC/1.0")
88 // To silence logging of health checks, register the health check handler before
89 // the logging handler
90 if opts.Logging.SilencePing {
91 chain = chain.Append(middleware.NewHealthCheck(healthCheckPaths, healthCheckUserAgents), LoggingHandler)
93 chain = chain.Append(LoggingHandler, middleware.NewHealthCheck(healthCheckPaths, healthCheckUserAgents))
97 Handler: chain.Then(oauthproxy),
99 stop: make(chan struct{}, 1),
101 // Observe signals in background goroutine.
103 sigint := make(chan os.Signal, 1)
104 signal.Notify(sigint, os.Interrupt, syscall.SIGTERM)
106 s.stop <- struct{}{} // notify having caught signal
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list