@@ -1,6 +1,7 @@
1package main
1package main
5 "crypto/tls"
6 "crypto/tls"
6 "encoding/base64"
7 "encoding/base64"
@@ -14,6 +15,7 @@ import (
15 "github.com/18F/hmacauth"
16 "github.com/18F/hmacauth"
16 "github.com/bitly/oauth2_proxy/providers"
17 "github.com/bitly/oauth2_proxy/providers"
18+ oidc "github.com/coreos/go-oidc"
19// Configuration Options that can be set by Command Line Flag, or Config File
21// Configuration Options that can be set by Command Line Flag, or Config File
@@ -63,6 +65,7 @@ type Options struct {
63 // These options allow for other providers besides Google, with
65 // These options allow for other providers besides Google, with
64 // potential overrides.
66 // potential overrides.
65 Provider string `flag:"provider" cfg:"provider"`
67 Provider string `flag:"provider" cfg:"provider"`
68+ OIDCIssuerURL string `flag:"oidc-issuer-url" cfg:"oidc_issuer_url"`
66 LoginURL string `flag:"login-url" cfg:"login_url"`
69 LoginURL string `flag:"login-url" cfg:"login_url"`
67 RedeemURL string `flag:"redeem-url" cfg:"redeem_url"`
70 RedeemURL string `flag:"redeem-url" cfg:"redeem_url"`
68 ProfileURL string `flag:"profile-url" cfg:"profile_url"`
71 ProfileURL string `flag:"profile-url" cfg:"profile_url"`
@@ -81,6 +84,7 @@ type Options struct {
81 CompiledRegex []*regexp.Regexp
84 CompiledRegex []*regexp.Regexp
82 provider providers.Provider
85 provider providers.Provider
83 signatureData *SignatureData
86 signatureData *SignatureData
87+ oidcVerifier *oidc.IDTokenVerifier
86type SignatureData struct {
90type SignatureData struct {
@@ -120,6 +124,14 @@ func parseURL(to_parse string, urltype string, msgs []string) (*url.URL, []strin
122func (o *Options) Validate() error {
126func (o *Options) Validate() error {
127+ if o.SSLInsecureSkipVerify {
128+ // TODO: Accept a certificate bundle.
129+ insecureTransport := &http.Transport{
130+ TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
132+ http.DefaultClient = &http.Client{Transport: insecureTransport}
123 msgs := make([]string, 0)
135 msgs := make([]string, 0)
124 if len(o.Upstreams) < 1 {
136 if len(o.Upstreams) < 1 {
125 msgs = append(msgs, "missing setting: upstream")
137 msgs = append(msgs, "missing setting: upstream")
@@ -137,6 +149,22 @@ func (o *Options) Validate() error {
137 msgs = append(msgs, "missing setting for email validation: email-domain or authenticated-emails-file required.\n use email-domain=* to authorize all email addresses")
149 msgs = append(msgs, "missing setting for email validation: email-domain or authenticated-emails-file required.\n use email-domain=* to authorize all email addresses")
152+ if o.OIDCIssuerURL != "" {
153+ // Configure discoverable provider data.
154+ provider, err := oidc.NewProvider(context.Background(), o.OIDCIssuerURL)
158+ o.oidcVerifier = provider.Verifier(&oidc.Config{
159+ ClientID: o.ClientID,
161+ o.LoginURL = provider.Endpoint().AuthURL
162+ o.RedeemURL = provider.Endpoint().TokenURL
164+ o.Scope = "openid email profile"
140 o.redirectURL, msgs = parseURL(o.RedirectURL, "redirect", msgs)
168 o.redirectURL, msgs = parseURL(o.RedirectURL, "redirect", msgs)
142 for _, u := range o.Upstreams {
170 for _, u := range o.Upstreams {
@@ -210,13 +238,6 @@ func (o *Options) Validate() error {
210 msgs = parseSignatureKey(o, msgs)
238 msgs = parseSignatureKey(o, msgs)
211 msgs = validateCookieName(o, msgs)
239 msgs = validateCookieName(o, msgs)
213− if o.SSLInsecureSkipVerify {
214− insecureTransport := &http.Transport{
215− TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
217− http.DefaultClient = &http.Client{Transport: insecureTransport}
220 if len(msgs) != 0 {
241 if len(msgs) != 0 {
221 return fmt.Errorf("Invalid configuration:\n %s",
242 return fmt.Errorf("Invalid configuration:\n %s",
222 strings.Join(msgs, "\n "))
243 strings.Join(msgs, "\n "))
@@ -252,6 +273,12 @@ func parseProviderInfo(o *Options, msgs []string) []string {
252 p.SetGroupRestriction(o.GoogleGroups, o.GoogleAdminEmail, file)
273 p.SetGroupRestriction(o.GoogleGroups, o.GoogleAdminEmail, file)
276+ case *providers.OIDCProvider:
277+ if o.oidcVerifier == nil {
278+ msgs = append(msgs, "oidc provider requires an oidc issuer URL")
280+ p.Verifier = o.oidcVerifier
256 return msgs
283 return msgs