12 "github.com/BurntSushi/toml"
13 "github.com/mreiferson/go-options"
17 log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
18 flagSet := flag.NewFlagSet("oauth2_proxy", flag.ExitOnError)
20 emailDomains := StringArray{}
21 upstreams := StringArray{}
22 skipAuthRegex := StringArray{}
23 googleGroups := StringArray{}
25 config := flagSet.String("config", "", "path to config file")
26 showVersion := flagSet.Bool("version", false, "print version string")
28 flagSet.String("http-address", "127.0.0.1:4180", "[http://]<addr>:<port> or unix://<path> to listen on for HTTP clients")
29 flagSet.String("https-address", ":443", "<addr>:<port> to listen on for HTTPS clients")
30 flagSet.String("tls-cert", "", "path to certificate file")
31 flagSet.String("tls-key", "", "path to private key file")
32 flagSet.String("redirect-url", "", "the OAuth Redirect URL. ie: \"https://internalapp.yourcompany.com/oauth2/callback\"")
33 flagSet.Bool("set-xauthrequest", false, "set X-Auth-Request-User and X-Auth-Request-Email response headers (useful in Nginx auth_request mode)")
34 flagSet.Var(&upstreams, "upstream", "the http url(s) of the upstream endpoint or file:// paths for static files. Routing is based on the path")
35 flagSet.Bool("pass-basic-auth", true, "pass HTTP Basic Auth, X-Forwarded-User and X-Forwarded-Email information to upstream")
36 flagSet.Bool("pass-user-headers", true, "pass X-Forwarded-User and X-Forwarded-Email information to upstream")
37 flagSet.String("basic-auth-password", "", "the password to set when passing the HTTP Basic Auth header")
38 flagSet.Bool("pass-access-token", false, "pass OAuth access_token to upstream via X-Forwarded-Access-Token header")
39 flagSet.Bool("pass-host-header", true, "pass the request Host Header to upstream")
40 flagSet.Var(&skipAuthRegex, "skip-auth-regex", "bypass authentication for requests path's that match (may be given multiple times)")
41 flagSet.Bool("skip-provider-button", false, "will skip sign-in-page to directly reach the next step: oauth/start")
42 flagSet.Bool("skip-auth-preflight", false, "will skip authentication for OPTIONS requests")
43 flagSet.Bool("ssl-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS")
45 flagSet.Var(&emailDomains, "email-domain", "authenticate emails with the specified domain (may be given multiple times). Use * to authenticate any email")
46 flagSet.String("azure-tenant", "common", "go to a tenant-specific or common (tenant-independent) endpoint.")
47 flagSet.String("github-org", "", "restrict logins to members of this organisation")
48 flagSet.String("github-team", "", "restrict logins to members of this team")
49 flagSet.Var(&googleGroups, "google-group", "restrict logins to members of this google group (may be given multiple times).")
50 flagSet.String("google-admin-email", "", "the google admin to impersonate for api calls")
51 flagSet.String("google-service-account-json", "", "the path to the service account json credentials")
52 flagSet.String("client-id", "", "the OAuth Client ID: ie: \"123456.apps.googleusercontent.com\"")
53 flagSet.String("client-secret", "", "the OAuth Client Secret")
54 flagSet.String("authenticated-emails-file", "", "authenticate against emails via file (one per line)")
55 flagSet.String("htpasswd-file", "", "additionally authenticate against a htpasswd file. Entries must be created with \"htpasswd -s\" for SHA encryption")
56 flagSet.Bool("display-htpasswd-form", true, "display username / password login form if an htpasswd file is provided")
57 flagSet.String("custom-templates-dir", "", "path to custom html templates")
58 flagSet.String("footer", "", "custom footer string. Use \"-\" to disable default footer.")
59 flagSet.String("proxy-prefix", "/oauth2", "the url root path that this proxy should be nested under (e.g. /<oauth2>/sign_in)")
61 flagSet.String("cookie-name", "_oauth2_proxy", "the name of the cookie that the oauth_proxy creates")
62 flagSet.String("cookie-secret", "", "the seed string for secure cookies (optionally base64 encoded)")
63 flagSet.String("cookie-domain", "", "an optional cookie domain to force cookies to (ie: .yourcompany.com)*")
64 flagSet.Duration("cookie-expire", time.Duration(168)*time.Hour, "expire timeframe for cookie")
65 flagSet.Duration("cookie-refresh", time.Duration(0), "refresh the cookie after this duration; 0 to disable")
66 flagSet.Bool("cookie-secure", true, "set secure (HTTPS) cookie flag")
67 flagSet.Bool("cookie-httponly", true, "set HttpOnly cookie flag")
69 flagSet.Bool("request-logging", true, "Log requests to stdout")
71 flagSet.String("provider", "google", "OAuth provider")
72 flagSet.String("login-url", "", "Authentication endpoint")
73 flagSet.String("redeem-url", "", "Token redemption endpoint")
74 flagSet.String("profile-url", "", "Profile access endpoint")
75 flagSet.String("resource", "", "The resource that is protected (Azure AD only)")
76 flagSet.String("validate-url", "", "Access token validation endpoint")
77 flagSet.String("scope", "", "OAuth scope specification")
78 flagSet.String("approval-prompt", "force", "OAuth approval_prompt")
80 flagSet.String("signature-key", "", "GAP-Signature request signature key (algorithm:secretkey)")
82 flagSet.Parse(os.Args[1:])
85 fmt.Printf("oauth2_proxy v%s (built with %s)\n", VERSION, runtime.Version())
91 cfg := make(EnvOptions)
93 _, err := toml.DecodeFile(*config, &cfg)
95 log.Fatalf("ERROR: failed to load config file %s - %s", *config, err)
98 cfg.LoadEnvForStruct(opts)
99 options.Resolve(opts, flagSet, cfg)
101 err := opts.Validate()
103 log.Printf("%s", err)
106 validator := NewValidator(opts.EmailDomains, opts.AuthenticatedEmailsFile)
107 oauthproxy := NewOAuthProxy(opts, validator)
109 if len(opts.EmailDomains) != 0 && opts.AuthenticatedEmailsFile == "" {
110 if len(opts.EmailDomains) > 1 {
111 oauthproxy.SignInMessage = fmt.Sprintf("Authenticate using one of the following domains: %v", strings.Join(opts.EmailDomains, ", "))
112 } else if opts.EmailDomains[0] != "*" {
113 oauthproxy.SignInMessage = fmt.Sprintf("Authenticate using %v", opts.EmailDomains[0])
117 if opts.HtpasswdFile != "" {
118 log.Printf("using htpasswd file %s", opts.HtpasswdFile)
119 oauthproxy.HtpasswdFile, err = NewHtpasswdFromFile(opts.HtpasswdFile)
120 oauthproxy.DisplayHtpasswdForm = opts.DisplayHtpasswdForm
122 log.Fatalf("FATAL: unable to open %s %s", opts.HtpasswdFile, err)
127 Handler: LoggingHandler(os.Stdout, oauthproxy, opts.RequestLogging),
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