@@ -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 o.CookieSecret == "" {
136 if o.CookieSecret == "" {
125 msgs = append(msgs, "missing setting: cookie-secret")
137 msgs = append(msgs, "missing setting: cookie-secret")
@@ -135,6 +147,22 @@ func (o *Options) Validate() error {
135 "\n use email-domain=* to authorize all email addresses")
147 "\n use email-domain=* to authorize all email addresses")
150+ if o.OIDCIssuerURL != "" {
151+ // Configure discoverable provider data.
152+ provider, err := oidc.NewProvider(context.Background(), o.OIDCIssuerURL)
156+ o.oidcVerifier = provider.Verifier(&oidc.Config{
157+ ClientID: o.ClientID,
159+ o.LoginURL = provider.Endpoint().AuthURL
160+ o.RedeemURL = provider.Endpoint().TokenURL
162+ o.Scope = "openid email profile"
138 o.redirectURL, msgs = parseURL(o.RedirectURL, "redirect", msgs)
166 o.redirectURL, msgs = parseURL(o.RedirectURL, "redirect", msgs)
140 for _, u := range o.Upstreams {
168 for _, u := range o.Upstreams {
@@ -207,13 +235,6 @@ func (o *Options) Validate() error {
207 msgs = parseSignatureKey(o, msgs)
235 msgs = parseSignatureKey(o, msgs)
208 msgs = validateCookieName(o, msgs)
236 msgs = validateCookieName(o, msgs)
210− if o.SSLInsecureSkipVerify {
211− insecureTransport := &http.Transport{
212− TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
214− http.DefaultClient = &http.Client{Transport: insecureTransport}
217 if len(msgs) != 0 {
238 if len(msgs) != 0 {
218 return fmt.Errorf("Invalid configuration:\n %s",
239 return fmt.Errorf("Invalid configuration:\n %s",
219 strings.Join(msgs, "\n "))
240 strings.Join(msgs, "\n "))
@@ -249,6 +270,12 @@ func parseProviderInfo(o *Options, msgs []string) []string {
249 p.SetGroupRestriction(o.GoogleGroups, o.GoogleAdminEmail, file)
270 p.SetGroupRestriction(o.GoogleGroups, o.GoogleAdminEmail, file)
273+ case *providers.OIDCProvider:
274+ if o.oidcVerifier == nil {
275+ msgs = append(msgs, "oidc provider requires an oidc issuer URL")
277+ p.Verifier = o.oidcVerifier
253 return msgs
280 return msgs