@@ -1,6 +1,7 @@
11package main
22
33import (
4+ "context"
45 "crypto"
56 "crypto/tls"
67 "encoding/base64"
@@ -14,6 +15,7 @@ import (
1415
1516 "github.com/18F/hmacauth"
1617 "github.com/bitly/oauth2_proxy/providers"
18+ oidc "github.com/coreos/go-oidc"
1719)
1820
1921// Configuration Options that can be set by Command Line Flag, or Config File
@@ -63,6 +65,7 @@ type Options struct {
6365 // These options allow for other providers besides Google, with
6466 // potential overrides.
6567 Provider string `flag:"provider" cfg:"provider"`
68+ OIDCIssuerURL string `flag:"oidc-issuer-url" cfg:"oidc_issuer_url"`
6669 LoginURL string `flag:"login-url" cfg:"login_url"`
6770 RedeemURL string `flag:"redeem-url" cfg:"redeem_url"`
6871 ProfileURL string `flag:"profile-url" cfg:"profile_url"`
@@ -81,6 +84,7 @@ type Options struct {
8184 CompiledRegex []*regexp.Regexp
8285 provider providers.Provider
8386 signatureData *SignatureData
87+ oidcVerifier *oidc.IDTokenVerifier
8488}
8589
8690type SignatureData struct {
@@ -120,6 +124,14 @@ func parseURL(to_parse string, urltype string, msgs []string) (*url.URL, []strin
120124}
121125
122126func (o *Options) Validate() error {
127+ if o.SSLInsecureSkipVerify {
128+ // TODO: Accept a certificate bundle.
129+ insecureTransport := &http.Transport{
130+ TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
131+ }
132+ http.DefaultClient = &http.Client{Transport: insecureTransport}
133+ }
134+
123135 msgs := make([]string, 0)
124136 if len(o.Upstreams) < 1 {
125137 msgs = append(msgs, "missing setting: upstream")
@@ -137,6 +149,22 @@ func (o *Options) Validate() error {
137149 msgs = append(msgs, "missing setting for email validation: email-domain or authenticated-emails-file required.\n use email-domain=* to authorize all email addresses")
138150 }
139151
152+ if o.OIDCIssuerURL != "" {
153+ // Configure discoverable provider data.
154+ provider, err := oidc.NewProvider(context.Background(), o.OIDCIssuerURL)
155+ if err != nil {
156+ return err
157+ }
158+ o.oidcVerifier = provider.Verifier(&oidc.Config{
159+ ClientID: o.ClientID,
160+ })
161+ o.LoginURL = provider.Endpoint().AuthURL
162+ o.RedeemURL = provider.Endpoint().TokenURL
163+ if o.Scope == "" {
164+ o.Scope = "openid email profile"
165+ }
166+ }
167+
140168 o.redirectURL, msgs = parseURL(o.RedirectURL, "redirect", msgs)
141169
142170 for _, u := range o.Upstreams {
@@ -210,13 +238,6 @@ func (o *Options) Validate() error {
210238 msgs = parseSignatureKey(o, msgs)
211239 msgs = validateCookieName(o, msgs)
212240
213− if o.SSLInsecureSkipVerify {
214− insecureTransport := &http.Transport{
215− TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
216− }
217− http.DefaultClient = &http.Client{Transport: insecureTransport}
218− }
219−
220241 if len(msgs) != 0 {
221242 return fmt.Errorf("Invalid configuration:\n %s",
222243 strings.Join(msgs, "\n "))
@@ -252,6 +273,12 @@ func parseProviderInfo(o *Options, msgs []string) []string {
252273 p.SetGroupRestriction(o.GoogleGroups, o.GoogleAdminEmail, file)
253274 }
254275 }
276+ case *providers.OIDCProvider:
277+ if o.oidcVerifier == nil {
278+ msgs = append(msgs, "oidc provider requires an oidc issuer URL")
279+ } else {
280+ p.Verifier = o.oidcVerifier
281+ }
255282 }
256283 return msgs
257284}