git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #164 from philips/go-code-style

Go code style

commite6e2dbe459c65ad084cbe1eb9d681e807d0973e7 authorJehiah Czebotar <jehiah@gmail.com> dateMon 9 Nov 2015, 09:37 (11 years ago) parent1b0144b6db1880
16 files changed+197−197
main.go+3−3 oauthproxy.go+43−43 oauthproxy_test.go+14−14 options.go+18−18 options_test.go+8−8 providers/github.go+6−6 providers/google.go+13−13 providers/google_test.go+20−20 providers/internal_util.go+2−2 providers/internal_util_test.go+3−3 providers/linkedin.go+9−9 providers/linkedin_test.go+19−19 providers/myusa.go+9−9 providers/myusa_test.go+21−21 providers/provider_data.go+4−4 providers/provider_default.go+5−5
main.go+3−3
@@ -66,8 +66,8 @@ func main() {
6666 flagSet.String("redeem-url", "", "Token redemption endpoint")
6767 flagSet.String("profile-url", "", "Profile access endpoint")
6868 flagSet.String("validate-url", "", "Access token validation endpoint")
69− flagSet.String("scope", "", "Oauth scope specification")
70− flagSet.String("approval-prompt", "force", "Oauth approval_prompt")
69+ flagSet.String("scope", "", "OAuth scope specification")
70+ flagSet.String("approval-prompt", "force", "OAuth approval_prompt")
7171
7272 flagSet.Parse(os.Args[1:])
7373
@@ -95,7 +95,7 @@ func main() {
9595 }
9696
9797 validator := NewValidator(opts.EmailDomains, opts.AuthenticatedEmailsFile)
98− oauthproxy := NewOauthProxy(opts, validator)
98+ oauthproxy := NewOAuthProxy(opts, validator)
9999
100100 if len(opts.EmailDomains) != 0 && opts.AuthenticatedEmailsFile == "" {
101101 if len(opts.EmailDomains) > 1 {
oauthproxy.go+43−43
@@ -18,7 +18,7 @@ import (
1818 "github.com/bitly/oauth2_proxy/providers"
1919)
2020
21−type OauthProxy struct {
21+type OAuthProxy struct {
2222 CookieSeed string
2323 CookieName string
2424 CookieDomain string
@@ -31,10 +31,10 @@ type OauthProxy struct {
3131 RobotsPath string
3232 PingPath string
3333 SignInPath string
34− OauthStartPath string
35− OauthCallbackPath string
34+ OAuthStartPath string
35+ OAuthCallbackPath string
3636
37− redirectUrl *url.URL // the url to receive requests at
37+ redirectURL *url.URL // the url to receive requests at
3838 provider providers.Provider
3939 ProxyPrefix string
4040 SignInMessage string
@@ -86,9 +86,9 @@ func NewFileServer(path string, filesystemPath string) (proxy http.Handler) {
8686 return http.StripPrefix(path, http.FileServer(http.Dir(filesystemPath)))
8787}
8888
89−func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
89+func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
9090 serveMux := http.NewServeMux()
91− for _, u := range opts.proxyUrls {
91+ for _, u := range opts.proxyURLs {
9292 path := u.Path
9393 switch u.Scheme {
9494 case "http", "https":
@@ -116,10 +116,10 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
116116 log.Printf("compiled skip-auth-regex => %q", u)
117117 }
118118
119− redirectUrl := opts.redirectUrl
120− redirectUrl.Path = fmt.Sprintf("%s/callback", opts.ProxyPrefix)
119+ redirectURL := opts.redirectURL
120+ redirectURL.Path = fmt.Sprintf("%s/callback", opts.ProxyPrefix)
121121
122− log.Printf("OauthProxy configured for %s Client ID: %s", opts.provider.Data().ProviderName, opts.ClientID)
122+ log.Printf("OAuthProxy configured for %s Client ID: %s", opts.provider.Data().ProviderName, opts.ClientID)
123123 domain := opts.CookieDomain
124124 if domain == "" {
125125 domain = "<default>"
@@ -141,7 +141,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
141141 }
142142 }
143143
144− return &OauthProxy{
144+ return &OAuthProxy{
145145 CookieName: opts.CookieName,
146146 CookieSeed: opts.CookieSecret,
147147 CookieDomain: opts.CookieDomain,
@@ -154,13 +154,13 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
154154 RobotsPath: "/robots.txt",
155155 PingPath: "/ping",
156156 SignInPath: fmt.Sprintf("%s/sign_in", opts.ProxyPrefix),
157− OauthStartPath: fmt.Sprintf("%s/start", opts.ProxyPrefix),
158− OauthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix),
157+ OAuthStartPath: fmt.Sprintf("%s/start", opts.ProxyPrefix),
158+ OAuthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix),
159159
160160 ProxyPrefix: opts.ProxyPrefix,
161161 provider: opts.provider,
162162 serveMux: serveMux,
163− redirectUrl: redirectUrl,
163+ redirectURL: redirectURL,
164164 skipAuthRegex: opts.SkipAuthRegex,
165165 compiledRegex: opts.CompiledRegex,
166166 PassBasicAuth: opts.PassBasicAuth,
@@ -171,13 +171,13 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
171171 }
172172}
173173
174−func (p *OauthProxy) GetRedirectURI(host string) string {
174+func (p *OAuthProxy) GetRedirectURI(host string) string {
175175 // default to the request Host if not set
176− if p.redirectUrl.Host != "" {
177− return p.redirectUrl.String()
176+ if p.redirectURL.Host != "" {
177+ return p.redirectURL.String()
178178 }
179179 var u url.URL
180− u = *p.redirectUrl
180+ u = *p.redirectURL
181181 if u.Scheme == "" {
182182 if p.CookieSecure {
183183 u.Scheme = "https"
@@ -189,16 +189,16 @@ func (p *OauthProxy) GetRedirectURI(host string) string {
189189 return u.String()
190190}
191191
192−func (p *OauthProxy) displayCustomLoginForm() bool {
192+func (p *OAuthProxy) displayCustomLoginForm() bool {
193193 return p.HtpasswdFile != nil && p.DisplayHtpasswdForm
194194}
195195
196−func (p *OauthProxy) redeemCode(host, code string) (s *providers.SessionState, err error) {
196+func (p *OAuthProxy) redeemCode(host, code string) (s *providers.SessionState, err error) {
197197 if code == "" {
198198 return nil, errors.New("missing code")
199199 }
200− redirectUri := p.GetRedirectURI(host)
201− s, err = p.provider.Redeem(redirectUri, code)
200+ redirectURI := p.GetRedirectURI(host)
201+ s, err = p.provider.Redeem(redirectURI, code)
202202 if err != nil {
203203 return
204204 }
@@ -209,7 +209,7 @@ func (p *OauthProxy) redeemCode(host, code string) (s *providers.SessionState, e
209209 return
210210}
211211
212−func (p *OauthProxy) MakeCookie(req *http.Request, value string, expiration time.Duration, now time.Time) *http.Cookie {
212+func (p *OAuthProxy) MakeCookie(req *http.Request, value string, expiration time.Duration, now time.Time) *http.Cookie {
213213 domain := req.Host
214214 if h, _, err := net.SplitHostPort(domain); err == nil {
215215 domain = h
@@ -235,15 +235,15 @@ func (p *OauthProxy) MakeCookie(req *http.Request, value string, expiration time
235235 }
236236}
237237
238−func (p *OauthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) {
238+func (p *OAuthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) {
239239 http.SetCookie(rw, p.MakeCookie(req, "", time.Hour*-1, time.Now()))
240240}
241241
242−func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val string) {
242+func (p *OAuthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val string) {
243243 http.SetCookie(rw, p.MakeCookie(req, val, p.CookieExpire, time.Now()))
244244}
245245
246−func (p *OauthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionState, time.Duration, error) {
246+func (p *OAuthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionState, time.Duration, error) {
247247 var age time.Duration
248248 c, err := req.Cookie(p.CookieName)
249249 if err != nil {
@@ -264,7 +264,7 @@ func (p *OauthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionSt
264264 return session, age, nil
265265}
266266
267−func (p *OauthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *providers.SessionState) error {
267+func (p *OAuthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *providers.SessionState) error {
268268 value, err := p.provider.CookieForSession(s, p.CookieCipher)
269269 if err != nil {
270270 return err
@@ -273,17 +273,17 @@ func (p *OauthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *p
273273 return nil
274274}
275275
276−func (p *OauthProxy) RobotsTxt(rw http.ResponseWriter) {
276+func (p *OAuthProxy) RobotsTxt(rw http.ResponseWriter) {
277277 rw.WriteHeader(http.StatusOK)
278278 fmt.Fprintf(rw, "User-agent: *\nDisallow: /")
279279}
280280
281−func (p *OauthProxy) PingPage(rw http.ResponseWriter) {
281+func (p *OAuthProxy) PingPage(rw http.ResponseWriter) {
282282 rw.WriteHeader(http.StatusOK)
283283 fmt.Fprintf(rw, "OK")
284284}
285285
286−func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) {
286+func (p *OAuthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) {
287287 log.Printf("ErrorPage %d %s %s", code, title, message)
288288 rw.WriteHeader(code)
289289 t := struct {
@@ -298,7 +298,7 @@ func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, m
298298 p.templates.ExecuteTemplate(rw, "error.html", t)
299299}
300300
301−func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) {
301+func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) {
302302 p.ClearCookie(rw, req)
303303 rw.WriteHeader(code)
304304
@@ -325,7 +325,7 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
325325 p.templates.ExecuteTemplate(rw, "sign_in.html", t)
326326}
327327
328−func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (string, bool) {
328+func (p *OAuthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (string, bool) {
329329 if req.Method != "POST" || p.HtpasswdFile == nil {
330330 return "", false
331331 }
@@ -342,7 +342,7 @@ func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (st
342342 return "", false
343343}
344344
345−func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) {
345+func (p *OAuthProxy) GetRedirect(req *http.Request) (string, error) {
346346 err := req.ParseForm()
347347
348348 if err != nil {
@@ -358,7 +358,7 @@ func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) {
358358 return redirect, err
359359}
360360
361−func (p *OauthProxy) IsWhitelistedPath(path string) (ok bool) {
361+func (p *OAuthProxy) IsWhitelistedPath(path string) (ok bool) {
362362 for _, u := range p.compiledRegex {
363363 ok = u.MatchString(path)
364364 if ok {
@@ -376,7 +376,7 @@ func getRemoteAddr(req *http.Request) (s string) {
376376 return
377377}
378378
379−func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
379+func (p *OAuthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
380380 switch path := req.URL.Path; {
381381 case path == p.RobotsPath:
382382 p.RobotsTxt(rw)
@@ -386,16 +386,16 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
386386 p.serveMux.ServeHTTP(rw, req)
387387 case path == p.SignInPath:
388388 p.SignIn(rw, req)
389− case path == p.OauthStartPath:
390− p.OauthStart(rw, req)
391− case path == p.OauthCallbackPath:
392− p.OauthCallback(rw, req)
389+ case path == p.OAuthStartPath:
390+ p.OAuthStart(rw, req)
391+ case path == p.OAuthCallbackPath:
392+ p.OAuthCallback(rw, req)
393393 default:
394394 p.Proxy(rw, req)
395395 }
396396}
397397
398−func (p *OauthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
398+func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
399399 redirect, err := p.GetRedirect(req)
400400 if err != nil {
401401 p.ErrorPage(rw, 500, "Internal Error", err.Error())
@@ -412,7 +412,7 @@ func (p *OauthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
412412 }
413413}
414414
415−func (p *OauthProxy) OauthStart(rw http.ResponseWriter, req *http.Request) {
415+func (p *OAuthProxy) OAuthStart(rw http.ResponseWriter, req *http.Request) {
416416 redirect, err := p.GetRedirect(req)
417417 if err != nil {
418418 p.ErrorPage(rw, 500, "Internal Error", err.Error())
@@ -422,7 +422,7 @@ func (p *OauthProxy) OauthStart(rw http.ResponseWriter, req *http.Request) {
422422 http.Redirect(rw, req, p.provider.GetLoginURL(redirectURI, redirect), 302)
423423}
424424
425−func (p *OauthProxy) OauthCallback(rw http.ResponseWriter, req *http.Request) {
425+func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
426426 remoteAddr := getRemoteAddr(req)
427427
428428 // finish the oauth cycle
@@ -465,7 +465,7 @@ func (p *OauthProxy) OauthCallback(rw http.ResponseWriter, req *http.Request) {
465465 }
466466}
467467
468−func (p *OauthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
468+func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
469469 var saveSession, clearSession, revalidated bool
470470 remoteAddr := getRemoteAddr(req)
471471
@@ -555,7 +555,7 @@ func (p *OauthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
555555 p.serveMux.ServeHTTP(rw, req)
556556}
557557
558−func (p *OauthProxy) CheckBasicAuth(req *http.Request) (*providers.SessionState, error) {
558+func (p *OAuthProxy) CheckBasicAuth(req *http.Request) (*providers.SessionState, error) {
559559 if p.HtpasswdFile == nil {
560560 return nil, nil
561561 }
oauthproxy_test.go+14−14
@@ -80,7 +80,7 @@ func TestRobotsTxt(t *testing.T) {
8080 opts.CookieSecret = "xyzzyplugh"
8181 opts.Validate()
8282
83− proxy := NewOauthProxy(opts, func(string) bool { return true })
83+ proxy := NewOAuthProxy(opts, func(string) bool { return true })
8484 rw := httptest.NewRecorder()
8585 req, _ := http.NewRequest("GET", "/robots.txt", nil)
8686 proxy.ServeHTTP(rw, req)
@@ -124,17 +124,17 @@ func TestBasicAuthPassword(t *testing.T) {
124124 opts.provider = &TestProvider{
125125 ProviderData: &providers.ProviderData{
126126 ProviderName: "Test Provider",
127− LoginUrl: &url.URL{
127+ LoginURL: &url.URL{
128128 Scheme: "http",
129129 Host: provider_url.Host,
130130 Path: "/oauth/authorize",
131131 },
132− RedeemUrl: &url.URL{
132+ RedeemURL: &url.URL{
133133 Scheme: "http",
134134 Host: provider_url.Host,
135135 Path: "/oauth/token",
136136 },
137− ProfileUrl: &url.URL{
137+ ProfileURL: &url.URL{
138138 Scheme: "http",
139139 Host: provider_url.Host,
140140 Path: "/api/v1/profile",
@@ -144,7 +144,7 @@ func TestBasicAuthPassword(t *testing.T) {
144144 EmailAddress: email_address,
145145 }
146146
147− proxy := NewOauthProxy(opts, func(email string) bool {
147+ proxy := NewOAuthProxy(opts, func(email string) bool {
148148 return email == email_address
149149 })
150150
@@ -199,7 +199,7 @@ func (tp *TestProvider) ValidateSessionState(session *providers.SessionState) bo
199199
200200type PassAccessTokenTest struct {
201201 provider_server *httptest.Server
202− proxy *OauthProxy
202+ proxy *OAuthProxy
203203 opts *Options
204204}
205205
@@ -245,17 +245,17 @@ func NewPassAccessTokenTest(opts PassAccessTokenTestOptions) *PassAccessTokenTes
245245 t.opts.provider = &TestProvider{
246246 ProviderData: &providers.ProviderData{
247247 ProviderName: "Test Provider",
248− LoginUrl: &url.URL{
248+ LoginURL: &url.URL{
249249 Scheme: "http",
250250 Host: provider_url.Host,
251251 Path: "/oauth/authorize",
252252 },
253− RedeemUrl: &url.URL{
253+ RedeemURL: &url.URL{
254254 Scheme: "http",
255255 Host: provider_url.Host,
256256 Path: "/oauth/token",
257257 },
258− ProfileUrl: &url.URL{
258+ ProfileURL: &url.URL{
259259 Scheme: "http",
260260 Host: provider_url.Host,
261261 Path: "/api/v1/profile",
@@ -265,7 +265,7 @@ func NewPassAccessTokenTest(opts PassAccessTokenTestOptions) *PassAccessTokenTes
265265 EmailAddress: email_address,
266266 }
267267
268− t.proxy = NewOauthProxy(t.opts, func(email string) bool {
268+ t.proxy = NewOAuthProxy(t.opts, func(email string) bool {
269269 return email == email_address
270270 })
271271 return t
@@ -360,7 +360,7 @@ func TestDoNotForwardAccessTokenUpstream(t *testing.T) {
360360
361361type SignInPageTest struct {
362362 opts *Options
363− proxy *OauthProxy
363+ proxy *OAuthProxy
364364 sign_in_regexp *regexp.Regexp
365365}
366366
@@ -375,7 +375,7 @@ func NewSignInPageTest() *SignInPageTest {
375375 sip_test.opts.ClientSecret = "xyzzyplugh"
376376 sip_test.opts.Validate()
377377
378− sip_test.proxy = NewOauthProxy(sip_test.opts, func(email string) bool {
378+ sip_test.proxy = NewOAuthProxy(sip_test.opts, func(email string) bool {
379379 return true
380380 })
381381 sip_test.sign_in_regexp = regexp.MustCompile(signInRedirectPattern)
@@ -425,7 +425,7 @@ func TestSignInPageDirectAccessRedirectsToRoot(t *testing.T) {
425425
426426type ProcessCookieTest struct {
427427 opts *Options
428− proxy *OauthProxy
428+ proxy *OAuthProxy
429429 rw *httptest.ResponseRecorder
430430 req *http.Request
431431 provider TestProvider
@@ -449,7 +449,7 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts) *ProcessCookieTest {
449449 pc_test.opts.CookieRefresh = time.Hour
450450 pc_test.opts.Validate()
451451
452− pc_test.proxy = NewOauthProxy(pc_test.opts, func(email string) bool {
452+ pc_test.proxy = NewOAuthProxy(pc_test.opts, func(email string) bool {
453453 return pc_test.validate_user
454454 })
455455 pc_test.proxy.provider = &TestProvider{
options.go+18−18
@@ -16,7 +16,7 @@ type Options struct {
1616 ProxyPrefix string `flag:"proxy-prefix" cfg:"proxy-prefix"`
1717 HttpAddress string `flag:"http-address" cfg:"http_address"`
1818 HttpsAddress string `flag:"https-address" cfg:"https_address"`
19− RedirectUrl string `flag:"redirect-url" cfg:"redirect_url"`
19+ RedirectURL string `flag:"redirect-url" cfg:"redirect_url"`
2020 ClientID string `flag:"client-id" cfg:"client_id" env:"OAUTH2_PROXY_CLIENT_ID"`
2121 ClientSecret string `flag:"client-secret" cfg:"client_secret" env:"OAUTH2_PROXY_CLIENT_SECRET"`
2222 TLSCertFile string `flag:"tls-cert" cfg:"tls_cert_file"`
@@ -51,18 +51,18 @@ type Options struct {
5151 // These options allow for other providers besides Google, with
5252 // potential overrides.
5353 Provider string `flag:"provider" cfg:"provider"`
54− LoginUrl string `flag:"login-url" cfg:"login_url"`
55− RedeemUrl string `flag:"redeem-url" cfg:"redeem_url"`
56− ProfileUrl string `flag:"profile-url" cfg:"profile_url"`
57− ValidateUrl string `flag:"validate-url" cfg:"validate_url"`
54+ LoginURL string `flag:"login-url" cfg:"login_url"`
55+ RedeemURL string `flag:"redeem-url" cfg:"redeem_url"`
56+ ProfileURL string `flag:"profile-url" cfg:"profile_url"`
57+ ValidateURL string `flag:"validate-url" cfg:"validate_url"`
5858 Scope string `flag:"scope" cfg:"scope"`
5959 ApprovalPrompt string `flag:"approval-prompt" cfg:"approval_prompt"`
6060
6161 RequestLogging bool `flag:"request-logging" cfg:"request_logging"`
6262
6363 // internal values that are set after config validation
64− redirectUrl *url.URL
65− proxyUrls []*url.URL
64+ redirectURL *url.URL
65+ proxyURLs []*url.URL
6666 CompiledRegex []*regexp.Regexp
6767 provider providers.Provider
6868}
@@ -86,7 +86,7 @@ func NewOptions() *Options {
8686 }
8787}
8888
89−func parseUrl(to_parse string, urltype string, msgs []string) (*url.URL, []string) {
89+func parseURL(to_parse string, urltype string, msgs []string) (*url.URL, []string) {
9090 parsed, err := url.Parse(to_parse)
9191 if err != nil {
9292 return nil, append(msgs, fmt.Sprintf(
@@ -113,19 +113,19 @@ func (o *Options) Validate() error {
113113 msgs = append(msgs, "missing setting for email validation: email-domain or authenticated-emails-file required.\n use email-domain=* to authorize all email addresses")
114114 }
115115
116− o.redirectUrl, msgs = parseUrl(o.RedirectUrl, "redirect", msgs)
116+ o.redirectURL, msgs = parseURL(o.RedirectURL, "redirect", msgs)
117117
118118 for _, u := range o.Upstreams {
119− upstreamUrl, err := url.Parse(u)
119+ upstreamURL, err := url.Parse(u)
120120 if err != nil {
121121 msgs = append(msgs, fmt.Sprintf(
122122 "error parsing upstream=%q %s",
123− upstreamUrl, err))
123+ upstreamURL, err))
124124 }
125− if upstreamUrl.Path == "" {
126− upstreamUrl.Path = "/"
125+ if upstreamURL.Path == "" {
126+ upstreamURL.Path = "/"
127127 }
128− o.proxyUrls = append(o.proxyUrls, upstreamUrl)
128+ o.proxyURLs = append(o.proxyURLs, upstreamURL)
129129 }
130130
131131 for _, u := range o.SkipAuthRegex {
@@ -189,10 +189,10 @@ func parseProviderInfo(o *Options, msgs []string) []string {
189189 ClientSecret: o.ClientSecret,
190190 ApprovalPrompt: o.ApprovalPrompt,
191191 }
192− p.LoginUrl, msgs = parseUrl(o.LoginUrl, "login", msgs)
193− p.RedeemUrl, msgs = parseUrl(o.RedeemUrl, "redeem", msgs)
194− p.ProfileUrl, msgs = parseUrl(o.ProfileUrl, "profile", msgs)
195− p.ValidateUrl, msgs = parseUrl(o.ValidateUrl, "validate", msgs)
192+ p.LoginURL, msgs = parseURL(o.LoginURL, "login", msgs)
193+ p.RedeemURL, msgs = parseURL(o.RedeemURL, "redeem", msgs)
194+ p.ProfileURL, msgs = parseURL(o.ProfileURL, "profile", msgs)
195+ p.ValidateURL, msgs = parseURL(o.ValidateURL, "validate", msgs)
196196
197197 o.provider = providers.New(o.Provider, p)
198198 switch p := o.provider.(type) {
options_test.go+8−8
@@ -73,16 +73,16 @@ func TestInitializedOptions(t *testing.T) {
7373
7474// Note that it's not worth testing nonparseable URLs, since url.Parse()
7575// seems to parse damn near anything.
76−func TestRedirectUrl(t *testing.T) {
76+func TestRedirectURL(t *testing.T) {
7777 o := testOptions()
78− o.RedirectUrl = "https://myhost.com/oauth2/callback"
78+ o.RedirectURL = "https://myhost.com/oauth2/callback"
7979 assert.Equal(t, nil, o.Validate())
8080 expected := &url.URL{
8181 Scheme: "https", Host: "myhost.com", Path: "/oauth2/callback"}
82− assert.Equal(t, expected, o.redirectUrl)
82+ assert.Equal(t, expected, o.redirectURL)
8383}
8484
85−func TestProxyUrls(t *testing.T) {
85+func TestProxyURLs(t *testing.T) {
8686 o := testOptions()
8787 o.Upstreams = append(o.Upstreams, "http://127.0.0.1:8081")
8888 assert.Equal(t, nil, o.Validate())
@@ -91,7 +91,7 @@ func TestProxyUrls(t *testing.T) {
9191 // note the '/' was added
9292 &url.URL{Scheme: "http", Host: "127.0.0.1:8081", Path: "/"},
9393 }
94− assert.Equal(t, expected, o.proxyUrls)
94+ assert.Equal(t, expected, o.proxyURLs)
9595}
9696
9797func TestCompiledRegex(t *testing.T) {
@@ -125,10 +125,10 @@ func TestDefaultProviderApiSettings(t *testing.T) {
125125 assert.Equal(t, nil, o.Validate())
126126 p := o.provider.Data()
127127 assert.Equal(t, "https://accounts.google.com/o/oauth2/auth?access_type=offline",
128− p.LoginUrl.String())
128+ p.LoginURL.String())
129129 assert.Equal(t, "https://www.googleapis.com/oauth2/v3/token",
130− p.RedeemUrl.String())
131− assert.Equal(t, "", p.ProfileUrl.String())
130+ p.RedeemURL.String())
131+ assert.Equal(t, "", p.ProfileURL.String())
132132 assert.Equal(t, "profile email", p.Scope)
133133}
134134
providers/github.go+6−6
@@ -17,22 +17,22 @@ type GitHubProvider struct {
1717
1818func NewGitHubProvider(p *ProviderData) *GitHubProvider {
1919 p.ProviderName = "GitHub"
20− if p.LoginUrl == nil || p.LoginUrl.String() == "" {
21− p.LoginUrl = &url.URL{
20+ if p.LoginURL == nil || p.LoginURL.String() == "" {
21+ p.LoginURL = &url.URL{
2222 Scheme: "https",
2323 Host: "github.com",
2424 Path: "/login/oauth/authorize",
2525 }
2626 }
27− if p.RedeemUrl == nil || p.RedeemUrl.String() == "" {
28− p.RedeemUrl = &url.URL{
27+ if p.RedeemURL == nil || p.RedeemURL.String() == "" {
28+ p.RedeemURL = &url.URL{
2929 Scheme: "https",
3030 Host: "github.com",
3131 Path: "/login/oauth/access_token",
3232 }
3333 }
34− if p.ValidateUrl == nil || p.ValidateUrl.String() == "" {
35− p.ValidateUrl = &url.URL{
34+ if p.ValidateURL == nil || p.ValidateURL.String() == "" {
35+ p.ValidateURL = &url.URL{
3636 Scheme: "https",
3737 Host: "api.github.com",
3838 Path: "/user/emails",
providers/google.go+13−13
@@ -21,7 +21,7 @@ import (
2121
2222type GoogleProvider struct {
2323 *ProviderData
24− RedeemRefreshUrl *url.URL
24+ RedeemRefreshURL *url.URL
2525 // GroupValidator is a function that determines if the passed email is in
2626 // the configured Google group.
2727 GroupValidator func(string) bool
@@ -29,21 +29,21 @@ type GoogleProvider struct {
2929
3030func NewGoogleProvider(p *ProviderData) *GoogleProvider {
3131 p.ProviderName = "Google"
32− if p.LoginUrl.String() == "" {
33− p.LoginUrl = &url.URL{Scheme: "https",
32+ if p.LoginURL.String() == "" {
33+ p.LoginURL = &url.URL{Scheme: "https",
3434 Host: "accounts.google.com",
3535 Path: "/o/oauth2/auth",
3636 // to get a refresh token. see https://developers.google.com/identity/protocols/OAuth2WebServer#offline
3737 RawQuery: "access_type=offline",
3838 }
3939 }
40− if p.RedeemUrl.String() == "" {
41− p.RedeemUrl = &url.URL{Scheme: "https",
40+ if p.RedeemURL.String() == "" {
41+ p.RedeemURL = &url.URL{Scheme: "https",
4242 Host: "www.googleapis.com",
4343 Path: "/oauth2/v3/token"}
4444 }
45− if p.ValidateUrl.String() == "" {
46− p.ValidateUrl = &url.URL{Scheme: "https",
45+ if p.ValidateURL.String() == "" {
46+ p.ValidateURL = &url.URL{Scheme: "https",
4747 Host: "www.googleapis.com",
4848 Path: "/oauth2/v1/tokeninfo"}
4949 }
@@ -96,20 +96,20 @@ func jwtDecodeSegment(seg string) ([]byte, error) {
9696 return base64.URLEncoding.DecodeString(seg)
9797}
9898
99−func (p *GoogleProvider) Redeem(redirectUrl, code string) (s *SessionState, err error) {
99+func (p *GoogleProvider) Redeem(redirectURL, code string) (s *SessionState, err error) {
100100 if code == "" {
101101 err = errors.New("missing code")
102102 return
103103 }
104104
105105 params := url.Values{}
106− params.Add("redirect_uri", redirectUrl)
106+ params.Add("redirect_uri", redirectURL)
107107 params.Add("client_id", p.ClientID)
108108 params.Add("client_secret", p.ClientSecret)
109109 params.Add("code", code)
110110 params.Add("grant_type", "authorization_code")
111111 var req *http.Request
112− req, err = http.NewRequest("POST", p.RedeemUrl.String(), bytes.NewBufferString(params.Encode()))
112+ req, err = http.NewRequest("POST", p.RedeemURL.String(), bytes.NewBufferString(params.Encode()))
113113 if err != nil {
114114 return
115115 }
@@ -127,7 +127,7 @@ func (p *GoogleProvider) Redeem(redirectUrl, code string) (s *SessionState, err
127127 }
128128
129129 if resp.StatusCode != 200 {
130− err = fmt.Errorf("got %d from %q %s", resp.StatusCode, p.RedeemUrl.String(), body)
130+ err = fmt.Errorf("got %d from %q %s", resp.StatusCode, p.RedeemURL.String(), body)
131131 return
132132 }
133133
@@ -281,7 +281,7 @@ func (p *GoogleProvider) redeemRefreshToken(refreshToken string) (token string,
281281 params.Add("refresh_token", refreshToken)
282282 params.Add("grant_type", "refresh_token")
283283 var req *http.Request
284− req, err = http.NewRequest("POST", p.RedeemUrl.String(), bytes.NewBufferString(params.Encode()))
284+ req, err = http.NewRequest("POST", p.RedeemURL.String(), bytes.NewBufferString(params.Encode()))
285285 if err != nil {
286286 return
287287 }
@@ -299,7 +299,7 @@ func (p *GoogleProvider) redeemRefreshToken(refreshToken string) (token string,
299299 }
300300
301301 if resp.StatusCode != 200 {
302− err = fmt.Errorf("got %d from %q %s", resp.StatusCode, p.RedeemUrl.String(), body)
302+ err = fmt.Errorf("got %d from %q %s", resp.StatusCode, p.RedeemURL.String(), body)
303303 return
304304 }
305305
providers/google_test.go+20−20
@@ -23,10 +23,10 @@ func newGoogleProvider() *GoogleProvider {
2323 return NewGoogleProvider(
2424 &ProviderData{
2525 ProviderName: "",
26− LoginUrl: &url.URL{},
27− RedeemUrl: &url.URL{},
28− ProfileUrl: &url.URL{},
29− ValidateUrl: &url.URL{},
26+ LoginURL: &url.URL{},
27+ RedeemURL: &url.URL{},
28+ ProfileURL: &url.URL{},
29+ ValidateURL: &url.URL{},
3030 Scope: ""})
3131}
3232
@@ -35,31 +35,31 @@ func TestGoogleProviderDefaults(t *testing.T) {
3535 assert.NotEqual(t, nil, p)
3636 assert.Equal(t, "Google", p.Data().ProviderName)
3737 assert.Equal(t, "https://accounts.google.com/o/oauth2/auth?access_type=offline",
38− p.Data().LoginUrl.String())
38+ p.Data().LoginURL.String())
3939 assert.Equal(t, "https://www.googleapis.com/oauth2/v3/token",
40− p.Data().RedeemUrl.String())
40+ p.Data().RedeemURL.String())
4141 assert.Equal(t, "https://www.googleapis.com/oauth2/v1/tokeninfo",
42− p.Data().ValidateUrl.String())
43− assert.Equal(t, "", p.Data().ProfileUrl.String())
42+ p.Data().ValidateURL.String())
43+ assert.Equal(t, "", p.Data().ProfileURL.String())
4444 assert.Equal(t, "profile email", p.Data().Scope)
4545}
4646
4747func TestGoogleProviderOverrides(t *testing.T) {
4848 p := NewGoogleProvider(
4949 &ProviderData{
50− LoginUrl: &url.URL{
50+ LoginURL: &url.URL{
5151 Scheme: "https",
5252 Host: "example.com",
5353 Path: "/oauth/auth"},
54− RedeemUrl: &url.URL{
54+ RedeemURL: &url.URL{
5555 Scheme: "https",
5656 Host: "example.com",
5757 Path: "/oauth/token"},
58− ProfileUrl: &url.URL{
58+ ProfileURL: &url.URL{
5959 Scheme: "https",
6060 Host: "example.com",
6161 Path: "/oauth/profile"},
62− ValidateUrl: &url.URL{
62+ ValidateURL: &url.URL{
6363 Scheme: "https",
6464 Host: "example.com",
6565 Path: "/oauth/tokeninfo"},
@@ -67,13 +67,13 @@ func TestGoogleProviderOverrides(t *testing.T) {
6767 assert.NotEqual(t, nil, p)
6868 assert.Equal(t, "Google", p.Data().ProviderName)
6969 assert.Equal(t, "https://example.com/oauth/auth",
70− p.Data().LoginUrl.String())
70+ p.Data().LoginURL.String())
7171 assert.Equal(t, "https://example.com/oauth/token",
72− p.Data().RedeemUrl.String())
72+ p.Data().RedeemURL.String())
7373 assert.Equal(t, "https://example.com/oauth/profile",
74− p.Data().ProfileUrl.String())
74+ p.Data().ProfileURL.String())
7575 assert.Equal(t, "https://example.com/oauth/tokeninfo",
76− p.Data().ValidateUrl.String())
76+ p.Data().ValidateURL.String())
7777 assert.Equal(t, "profile", p.Data().Scope)
7878}
7979
@@ -94,7 +94,7 @@ func TestGoogleProviderGetEmailAddress(t *testing.T) {
9494 })
9595 assert.Equal(t, nil, err)
9696 var server *httptest.Server
97− p.RedeemUrl, server = newRedeemServer(body)
97+ p.RedeemURL, server = newRedeemServer(body)
9898 defer server.Close()
9999
100100 session, err := p.Redeem("http://redirect/", "code1234")
@@ -131,7 +131,7 @@ func TestGoogleProviderGetEmailAddressInvalidEncoding(t *testing.T) {
131131 })
132132 assert.Equal(t, nil, err)
133133 var server *httptest.Server
134− p.RedeemUrl, server = newRedeemServer(body)
134+ p.RedeemURL, server = newRedeemServer(body)
135135 defer server.Close()
136136
137137 session, err := p.Redeem("http://redirect/", "code1234")
@@ -150,7 +150,7 @@ func TestGoogleProviderGetEmailAddressInvalidJson(t *testing.T) {
150150 })
151151 assert.Equal(t, nil, err)
152152 var server *httptest.Server
153− p.RedeemUrl, server = newRedeemServer(body)
153+ p.RedeemURL, server = newRedeemServer(body)
154154 defer server.Close()
155155
156156 session, err := p.Redeem("http://redirect/", "code1234")
@@ -169,7 +169,7 @@ func TestGoogleProviderGetEmailAddressEmailMissing(t *testing.T) {
169169 })
170170 assert.Equal(t, nil, err)
171171 var server *httptest.Server
172− p.RedeemUrl, server = newRedeemServer(body)
172+ p.RedeemURL, server = newRedeemServer(body)
173173 defer server.Close()
174174
175175 session, err := p.Redeem("http://redirect/", "code1234")
providers/internal_util.go+2−2
@@ -11,10 +11,10 @@ import (
1111
1212// validateToken returns true if token is valid
1313func validateToken(p Provider, access_token string, header http.Header) bool {
14− if access_token == "" || p.Data().ValidateUrl == nil {
14+ if access_token == "" || p.Data().ValidateURL == nil {
1515 return false
1616 }
17− endpoint := p.Data().ValidateUrl.String()
17+ endpoint := p.Data().ValidateURL.String()
1818 if len(header) == 0 {
1919 params := url.Values{"access_token": {access_token}}
2020 endpoint = endpoint + "?" + params.Encode()
providers/internal_util_test.go+3−3
@@ -63,7 +63,7 @@ func NewValidateSessionStateTest() *ValidateSessionStateTest {
6363 backend_url, _ := url.Parse(vt_test.backend.URL)
6464 vt_test.provider = &ValidateSessionStateTestProvider{
6565 ProviderData: &ProviderData{
66− ValidateUrl: &url.URL{
66+ ValidateURL: &url.URL{
6767 Scheme: "http",
6868 Host: backend_url.Host,
6969 Path: "/oauth/tokeninfo",
@@ -99,10 +99,10 @@ func TestValidateSessionStateEmptyToken(t *testing.T) {
9999 assert.Equal(t, false, validateToken(vt_test.provider, "", nil))
100100}
101101
102−func TestValidateSessionStateEmptyValidateUrl(t *testing.T) {
102+func TestValidateSessionStateEmptyValidateURL(t *testing.T) {
103103 vt_test := NewValidateSessionStateTest()
104104 defer vt_test.Close()
105− vt_test.provider.Data().ValidateUrl = nil
105+ vt_test.provider.Data().ValidateURL = nil
106106 assert.Equal(t, false, validateToken(vt_test.provider, "foobar", nil))
107107}
108108
providers/linkedin.go+9−9
@@ -15,23 +15,23 @@ type LinkedInProvider struct {
1515
1616func NewLinkedInProvider(p *ProviderData) *LinkedInProvider {
1717 p.ProviderName = "LinkedIn"
18− if p.LoginUrl.String() == "" {
19− p.LoginUrl = &url.URL{Scheme: "https",
18+ if p.LoginURL.String() == "" {
19+ p.LoginURL = &url.URL{Scheme: "https",
2020 Host: "www.linkedin.com",
2121 Path: "/uas/oauth2/authorization"}
2222 }
23− if p.RedeemUrl.String() == "" {
24− p.RedeemUrl = &url.URL{Scheme: "https",
23+ if p.RedeemURL.String() == "" {
24+ p.RedeemURL = &url.URL{Scheme: "https",
2525 Host: "www.linkedin.com",
2626 Path: "/uas/oauth2/accessToken"}
2727 }
28− if p.ProfileUrl.String() == "" {
29− p.ProfileUrl = &url.URL{Scheme: "https",
28+ if p.ProfileURL.String() == "" {
29+ p.ProfileURL = &url.URL{Scheme: "https",
3030 Host: "www.linkedin.com",
3131 Path: "/v1/people/~/email-address"}
3232 }
33− if p.ValidateUrl.String() == "" {
34− p.ValidateUrl = p.ProfileUrl
33+ if p.ValidateURL.String() == "" {
34+ p.ValidateURL = p.ProfileURL
3535 }
3636 if p.Scope == "" {
3737 p.Scope = "r_emailaddress r_basicprofile"
@@ -51,7 +51,7 @@ func (p *LinkedInProvider) GetEmailAddress(s *SessionState) (string, error) {
5151 if s.AccessToken == "" {
5252 return "", errors.New("missing access token")
5353 }
54− req, err := http.NewRequest("GET", p.ProfileUrl.String()+"?format=json", nil)
54+ req, err := http.NewRequest("GET", p.ProfileURL.String()+"?format=json", nil)
5555 if err != nil {
5656 return "", err
5757 }
providers/linkedin_test.go+19−19
@@ -12,15 +12,15 @@ func testLinkedInProvider(hostname string) *LinkedInProvider {
1212 p := NewLinkedInProvider(
1313 &ProviderData{
1414 ProviderName: "",
15− LoginUrl: &url.URL{},
16− RedeemUrl: &url.URL{},
17− ProfileUrl: &url.URL{},
18− ValidateUrl: &url.URL{},
15+ LoginURL: &url.URL{},
16+ RedeemURL: &url.URL{},
17+ ProfileURL: &url.URL{},
18+ ValidateURL: &url.URL{},
1919 Scope: ""})
2020 if hostname != "" {
21− updateUrl(p.Data().LoginUrl, hostname)
22− updateUrl(p.Data().RedeemUrl, hostname)
23− updateUrl(p.Data().ProfileUrl, hostname)
21+ updateURL(p.Data().LoginURL, hostname)
22+ updateURL(p.Data().RedeemURL, hostname)
23+ updateURL(p.Data().ProfileURL, hostname)
2424 }
2525 return p
2626}
@@ -47,32 +47,32 @@ func TestLinkedInProviderDefaults(t *testing.T) {
4747 assert.NotEqual(t, nil, p)
4848 assert.Equal(t, "LinkedIn", p.Data().ProviderName)
4949 assert.Equal(t, "https://www.linkedin.com/uas/oauth2/authorization",
50− p.Data().LoginUrl.String())
50+ p.Data().LoginURL.String())
5151 assert.Equal(t, "https://www.linkedin.com/uas/oauth2/accessToken",
52− p.Data().RedeemUrl.String())
52+ p.Data().RedeemURL.String())
5353 assert.Equal(t, "https://www.linkedin.com/v1/people/~/email-address",
54− p.Data().ProfileUrl.String())
54+ p.Data().ProfileURL.String())
5555 assert.Equal(t, "https://www.linkedin.com/v1/people/~/email-address",
56− p.Data().ValidateUrl.String())
56+ p.Data().ValidateURL.String())
5757 assert.Equal(t, "r_emailaddress r_basicprofile", p.Data().Scope)
5858}
5959
6060func TestLinkedInProviderOverrides(t *testing.T) {
6161 p := NewLinkedInProvider(
6262 &ProviderData{
63− LoginUrl: &url.URL{
63+ LoginURL: &url.URL{
6464 Scheme: "https",
6565 Host: "example.com",
6666 Path: "/oauth/auth"},
67− RedeemUrl: &url.URL{
67+ RedeemURL: &url.URL{
6868 Scheme: "https",
6969 Host: "example.com",
7070 Path: "/oauth/token"},
71− ProfileUrl: &url.URL{
71+ ProfileURL: &url.URL{
7272 Scheme: "https",
7373 Host: "example.com",
7474 Path: "/oauth/profile"},
75− ValidateUrl: &url.URL{
75+ ValidateURL: &url.URL{
7676 Scheme: "https",
7777 Host: "example.com",
7878 Path: "/oauth/tokeninfo"},
@@ -80,13 +80,13 @@ func TestLinkedInProviderOverrides(t *testing.T) {
8080 assert.NotEqual(t, nil, p)
8181 assert.Equal(t, "LinkedIn", p.Data().ProviderName)
8282 assert.Equal(t, "https://example.com/oauth/auth",
83− p.Data().LoginUrl.String())
83+ p.Data().LoginURL.String())
8484 assert.Equal(t, "https://example.com/oauth/token",
85− p.Data().RedeemUrl.String())
85+ p.Data().RedeemURL.String())
8686 assert.Equal(t, "https://example.com/oauth/profile",
87− p.Data().ProfileUrl.String())
87+ p.Data().ProfileURL.String())
8888 assert.Equal(t, "https://example.com/oauth/tokeninfo",
89− p.Data().ValidateUrl.String())
89+ p.Data().ValidateURL.String())
9090 assert.Equal(t, "profile", p.Data().Scope)
9191}
9292
providers/myusa.go+9−9
@@ -16,23 +16,23 @@ func NewMyUsaProvider(p *ProviderData) *MyUsaProvider {
1616 const myUsaHost string = "alpha.my.usa.gov"
1717
1818 p.ProviderName = "MyUSA"
19− if p.LoginUrl.String() == "" {
20− p.LoginUrl = &url.URL{Scheme: "https",
19+ if p.LoginURL.String() == "" {
20+ p.LoginURL = &url.URL{Scheme: "https",
2121 Host: myUsaHost,
2222 Path: "/oauth/authorize"}
2323 }
24− if p.RedeemUrl.String() == "" {
25− p.RedeemUrl = &url.URL{Scheme: "https",
24+ if p.RedeemURL.String() == "" {
25+ p.RedeemURL = &url.URL{Scheme: "https",
2626 Host: myUsaHost,
2727 Path: "/oauth/token"}
2828 }
29− if p.ProfileUrl.String() == "" {
30− p.ProfileUrl = &url.URL{Scheme: "https",
29+ if p.ProfileURL.String() == "" {
30+ p.ProfileURL = &url.URL{Scheme: "https",
3131 Host: myUsaHost,
3232 Path: "/api/v1/profile"}
3333 }
34− if p.ValidateUrl.String() == "" {
35− p.ValidateUrl = &url.URL{Scheme: "https",
34+ if p.ValidateURL.String() == "" {
35+ p.ValidateURL = &url.URL{Scheme: "https",
3636 Host: myUsaHost,
3737 Path: "/api/v1/tokeninfo"}
3838 }
@@ -44,7 +44,7 @@ func NewMyUsaProvider(p *ProviderData) *MyUsaProvider {
4444
4545func (p *MyUsaProvider) GetEmailAddress(s *SessionState) (string, error) {
4646 req, err := http.NewRequest("GET",
47− p.ProfileUrl.String()+"?access_token="+s.AccessToken, nil)
47+ p.ProfileURL.String()+"?access_token="+s.AccessToken, nil)
4848 if err != nil {
4949 log.Printf("failed building request %s", err)
5050 return "", err
providers/myusa_test.go+21−21
@@ -9,7 +9,7 @@ import (
99 "github.com/bmizerany/assert"
1010)
1111
12−func updateUrl(url *url.URL, hostname string) {
12+func updateURL(url *url.URL, hostname string) {
1313 url.Scheme = "http"
1414 url.Host = hostname
1515}
@@ -18,16 +18,16 @@ func testMyUsaProvider(hostname string) *MyUsaProvider {
1818 p := NewMyUsaProvider(
1919 &ProviderData{
2020 ProviderName: "",
21− LoginUrl: &url.URL{},
22− RedeemUrl: &url.URL{},
23− ProfileUrl: &url.URL{},
24− ValidateUrl: &url.URL{},
21+ LoginURL: &url.URL{},
22+ RedeemURL: &url.URL{},
23+ ProfileURL: &url.URL{},
24+ ValidateURL: &url.URL{},
2525 Scope: ""})
2626 if hostname != "" {
27− updateUrl(p.Data().LoginUrl, hostname)
28− updateUrl(p.Data().RedeemUrl, hostname)
29− updateUrl(p.Data().ProfileUrl, hostname)
30− updateUrl(p.Data().ValidateUrl, hostname)
27+ updateURL(p.Data().LoginURL, hostname)
28+ updateURL(p.Data().RedeemURL, hostname)
29+ updateURL(p.Data().ProfileURL, hostname)
30+ updateURL(p.Data().ValidateURL, hostname)
3131 }
3232 return p
3333}
@@ -53,32 +53,32 @@ func TestMyUsaProviderDefaults(t *testing.T) {
5353 assert.NotEqual(t, nil, p)
5454 assert.Equal(t, "MyUSA", p.Data().ProviderName)
5555 assert.Equal(t, "https://alpha.my.usa.gov/oauth/authorize",
56− p.Data().LoginUrl.String())
56+ p.Data().LoginURL.String())
5757 assert.Equal(t, "https://alpha.my.usa.gov/oauth/token",
58− p.Data().RedeemUrl.String())
58+ p.Data().RedeemURL.String())
5959 assert.Equal(t, "https://alpha.my.usa.gov/api/v1/profile",
60− p.Data().ProfileUrl.String())
60+ p.Data().ProfileURL.String())
6161 assert.Equal(t, "https://alpha.my.usa.gov/api/v1/tokeninfo",
62− p.Data().ValidateUrl.String())
62+ p.Data().ValidateURL.String())
6363 assert.Equal(t, "profile.email", p.Data().Scope)
6464}
6565
6666func TestMyUsaProviderOverrides(t *testing.T) {
6767 p := NewMyUsaProvider(
6868 &ProviderData{
69− LoginUrl: &url.URL{
69+ LoginURL: &url.URL{
7070 Scheme: "https",
7171 Host: "example.com",
7272 Path: "/oauth/auth"},
73− RedeemUrl: &url.URL{
73+ RedeemURL: &url.URL{
7474 Scheme: "https",
7575 Host: "example.com",
7676 Path: "/oauth/token"},
77− ProfileUrl: &url.URL{
77+ ProfileURL: &url.URL{
7878 Scheme: "https",
7979 Host: "example.com",
8080 Path: "/oauth/profile"},
81− ValidateUrl: &url.URL{
81+ ValidateURL: &url.URL{
8282 Scheme: "https",
8383 Host: "example.com",
8484 Path: "/oauth/tokeninfo"},
@@ -86,13 +86,13 @@ func TestMyUsaProviderOverrides(t *testing.T) {
8686 assert.NotEqual(t, nil, p)
8787 assert.Equal(t, "MyUSA", p.Data().ProviderName)
8888 assert.Equal(t, "https://example.com/oauth/auth",
89− p.Data().LoginUrl.String())
89+ p.Data().LoginURL.String())
9090 assert.Equal(t, "https://example.com/oauth/token",
91− p.Data().RedeemUrl.String())
91+ p.Data().RedeemURL.String())
9292 assert.Equal(t, "https://example.com/oauth/profile",
93− p.Data().ProfileUrl.String())
93+ p.Data().ProfileURL.String())
9494 assert.Equal(t, "https://example.com/oauth/tokeninfo",
95− p.Data().ValidateUrl.String())
95+ p.Data().ValidateURL.String())
9696 assert.Equal(t, "profile", p.Data().Scope)
9797}
9898
providers/provider_data.go+4−4
@@ -8,10 +8,10 @@ type ProviderData struct {
88 ProviderName string
99 ClientID string
1010 ClientSecret string
11− LoginUrl *url.URL
12− RedeemUrl *url.URL
13− ProfileUrl *url.URL
14− ValidateUrl *url.URL
11+ LoginURL *url.URL
12+ RedeemURL *url.URL
13+ ProfileURL *url.URL
14+ ValidateURL *url.URL
1515 Scope string
1616 ApprovalPrompt string
1717}
providers/provider_default.go+5−5
@@ -13,20 +13,20 @@ import (
1313 "github.com/bitly/oauth2_proxy/cookie"
1414)
1515
16−func (p *ProviderData) Redeem(redirectUrl, code string) (s *SessionState, err error) {
16+func (p *ProviderData) Redeem(redirectURL, code string) (s *SessionState, err error) {
1717 if code == "" {
1818 err = errors.New("missing code")
1919 return
2020 }
2121
2222 params := url.Values{}
23− params.Add("redirect_uri", redirectUrl)
23+ params.Add("redirect_uri", redirectURL)
2424 params.Add("client_id", p.ClientID)
2525 params.Add("client_secret", p.ClientSecret)
2626 params.Add("code", code)
2727 params.Add("grant_type", "authorization_code")
2828 var req *http.Request
29− req, err = http.NewRequest("POST", p.RedeemUrl.String(), bytes.NewBufferString(params.Encode()))
29+ req, err = http.NewRequest("POST", p.RedeemURL.String(), bytes.NewBufferString(params.Encode()))
3030 if err != nil {
3131 return
3232 }
@@ -45,7 +45,7 @@ func (p *ProviderData) Redeem(redirectUrl, code string) (s *SessionState, err er
4545 }
4646
4747 if resp.StatusCode != 200 {
48− err = fmt.Errorf("got %d from %q %s", resp.StatusCode, p.RedeemUrl.String(), body)
48+ err = fmt.Errorf("got %d from %q %s", resp.StatusCode, p.RedeemURL.String(), body)
4949 return
5050 }
5151
@@ -77,7 +77,7 @@ func (p *ProviderData) Redeem(redirectUrl, code string) (s *SessionState, err er
7777// GetLoginURL with typical oauth parameters
7878func (p *ProviderData) GetLoginURL(redirectURI, finalRedirect string) string {
7979 var a url.URL
80− a = *p.LoginUrl
80+ a = *p.LoginURL
8181 params, _ := url.ParseQuery(a.RawQuery)
8282 params.Set("redirect_uri", redirectURI)
8383 params.Set("approval_prompt", p.ApprovalPrompt)