@@ -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 o.CookieSecret == "" {
125137 msgs = append(msgs, "missing setting: cookie-secret")
@@ -135,6 +147,22 @@ func (o *Options) Validate() error {
135147 "\n use email-domain=* to authorize all email addresses")
136148 }
137149
150+ if o.OIDCIssuerURL != "" {
151+ // Configure discoverable provider data.
152+ provider, err := oidc.NewProvider(context.Background(), o.OIDCIssuerURL)
153+ if err != nil {
154+ return err
155+ }
156+ o.oidcVerifier = provider.Verifier(&oidc.Config{
157+ ClientID: o.ClientID,
158+ })
159+ o.LoginURL = provider.Endpoint().AuthURL
160+ o.RedeemURL = provider.Endpoint().TokenURL
161+ if o.Scope == "" {
162+ o.Scope = "openid email profile"
163+ }
164+ }
165+
138166 o.redirectURL, msgs = parseURL(o.RedirectURL, "redirect", msgs)
139167
140168 for _, u := range o.Upstreams {
@@ -207,13 +235,6 @@ func (o *Options) Validate() error {
207235 msgs = parseSignatureKey(o, msgs)
208236 msgs = validateCookieName(o, msgs)
209237
210− if o.SSLInsecureSkipVerify {
211− insecureTransport := &http.Transport{
212− TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
213− }
214− http.DefaultClient = &http.Client{Transport: insecureTransport}
215− }
216−
217238 if len(msgs) != 0 {
218239 return fmt.Errorf("Invalid configuration:\n %s",
219240 strings.Join(msgs, "\n "))
@@ -249,6 +270,12 @@ func parseProviderInfo(o *Options, msgs []string) []string {
249270 p.SetGroupRestriction(o.GoogleGroups, o.GoogleAdminEmail, file)
250271 }
251272 }
273+ case *providers.OIDCProvider:
274+ if o.oidcVerifier == nil {
275+ msgs = append(msgs, "oidc provider requires an oidc issuer URL")
276+ } else {
277+ p.Verifier = o.oidcVerifier
278+ }
252279 }
253280 return msgs
254281}