You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-12-01 22:51:45 +02:00
Integrate Provider into Options and OauthProxy
This commit is contained in:
37
options.go
37
options.go
@@ -6,6 +6,8 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bitly/google_auth_proxy/providers"
|
||||
)
|
||||
|
||||
// Configuration Options that can be set by Command Line Flag, or Config File
|
||||
@@ -33,12 +35,21 @@ type Options struct {
|
||||
PassBasicAuth bool `flag:"pass-basic-auth" cfg:"pass_basic_auth"`
|
||||
PassHostHeader bool `flag:"pass-host-header" cfg:"pass_host_header"`
|
||||
|
||||
// These options allow for other providers besides Google, with
|
||||
// potential overrides.
|
||||
Provider string `flag:"provider" cfg:"provider"`
|
||||
LoginUrl string `flag:"login-url" cfg:"login_url"`
|
||||
RedeemUrl string `flag:"redeem-url" cfg:"redeem_url"`
|
||||
ProfileUrl string `flag:"profile-url" cfg:"profile_url"`
|
||||
Scope string `flag:"scope" cfg:"scope"`
|
||||
|
||||
RequestLogging bool `flag:"request-logging" cfg:"request_logging"`
|
||||
|
||||
// internal values that are set after config validation
|
||||
redirectUrl *url.URL
|
||||
proxyUrls []*url.URL
|
||||
CompiledRegex []*regexp.Regexp
|
||||
provider providers.Provider
|
||||
}
|
||||
|
||||
func NewOptions() *Options {
|
||||
@@ -55,6 +66,15 @@ func NewOptions() *Options {
|
||||
}
|
||||
}
|
||||
|
||||
func parseUrl(to_parse string, urltype string, msgs []string) (*url.URL, []string) {
|
||||
parsed, err := url.Parse(to_parse)
|
||||
if err != nil {
|
||||
return nil, append(msgs, fmt.Sprintf(
|
||||
"error parsing %s-url=%q %s", urltype, to_parse, err))
|
||||
}
|
||||
return parsed, msgs
|
||||
}
|
||||
|
||||
func (o *Options) Validate() error {
|
||||
msgs := make([]string, 0)
|
||||
if len(o.Upstreams) < 1 {
|
||||
@@ -70,12 +90,7 @@ func (o *Options) Validate() error {
|
||||
msgs = append(msgs, "missing setting: client-secret")
|
||||
}
|
||||
|
||||
redirectUrl, err := url.Parse(o.RedirectUrl)
|
||||
if err != nil {
|
||||
msgs = append(msgs, fmt.Sprintf(
|
||||
"error parsing redirect-url=%q %s", o.RedirectUrl, err))
|
||||
}
|
||||
o.redirectUrl = redirectUrl
|
||||
o.redirectUrl, msgs = parseUrl(o.RedirectUrl, "redirect", msgs)
|
||||
|
||||
for _, u := range o.Upstreams {
|
||||
upstreamUrl, err := url.Parse(u)
|
||||
@@ -98,6 +113,7 @@ func (o *Options) Validate() error {
|
||||
}
|
||||
o.CompiledRegex = append(o.CompiledRegex, CompiledRegex)
|
||||
}
|
||||
msgs = parseProviderInfo(o, msgs)
|
||||
|
||||
if len(msgs) != 0 {
|
||||
return fmt.Errorf("Invalid configuration:\n %s",
|
||||
@@ -105,3 +121,12 @@ func (o *Options) Validate() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseProviderInfo(o *Options, msgs []string) []string {
|
||||
p := &providers.ProviderData{Scope: o.Scope}
|
||||
p.LoginUrl, msgs = parseUrl(o.LoginUrl, "login", msgs)
|
||||
p.RedeemUrl, msgs = parseUrl(o.RedeemUrl, "redeem", msgs)
|
||||
p.ProfileUrl, msgs = parseUrl(o.ProfileUrl, "profile", msgs)
|
||||
o.provider = providers.New(o.Provider, p)
|
||||
return msgs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user