git.iko.soy/typeable/oauth2-proxy
on master help sign in
chore(goconsts): use proper constants for http methods
9a14186Jan Larwig
oauthproxy.go+2−2
@@ -587,7 +587,7 @@ func (p *OAuthProxy) ErrorPage(rw http.ResponseWriter, req *http.Request, code i
587
587
588// IsAllowedRequest is used to check if auth should be skipped for this request
588// IsAllowedRequest is used to check if auth should be skipped for this request
589func (p *OAuthProxy) IsAllowedRequest(req *http.Request) bool {
589func (p *OAuthProxy) IsAllowedRequest(req *http.Request) bool {
590− isPreflightRequestAllowed := p.skipAuthPreflight && req.Method == "OPTIONS"
590+ isPreflightRequestAllowed := p.skipAuthPreflight && req.Method == http.MethodOptions
591 return isPreflightRequestAllowed || p.isAllowedRoute(req) || p.isTrustedIP(req)
591 return isPreflightRequestAllowed || p.isAllowedRoute(req) || p.isTrustedIP(req)
592}
592}
593
593
@@ -669,7 +669,7 @@ func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
669
669
670// ManualSignIn handles basic auth logins to the proxy
670// ManualSignIn handles basic auth logins to the proxy
671func (p *OAuthProxy) ManualSignIn(req *http.Request) (string, bool, int) {
671func (p *OAuthProxy) ManualSignIn(req *http.Request) (string, bool, int) {
672− if req.Method != "POST" || p.basicAuthValidator == nil {
672+ if req.Method != http.MethodPost || p.basicAuthValidator == nil {
673 return "", false, http.StatusOK
673 return "", false, http.StatusOK
674 }
674 }
675 user := req.FormValue("username")
675 user := req.FormValue("username")
oauthproxy_test.go+75−75
@@ -54,7 +54,7 @@ func TestRobotsTxt(t *testing.T) {
54 t.Fatal(err)
54 t.Fatal(err)
55 }
55 }
56 rw := httptest.NewRecorder()
56 rw := httptest.NewRecorder()
57− req, _ := http.NewRequest("GET", "/robots.txt", nil)
57+ req, _ := http.NewRequest(http.MethodGet, "/robots.txt", nil)
58 proxy.ServeHTTP(rw, req)
58 proxy.ServeHTTP(rw, req)
59 assert.Equal(t, 200, rw.Code)
59 assert.Equal(t, 200, rw.Code)
60 assert.Equal(t, "User-agent: *\nDisallow: /\n", rw.Body.String())
60 assert.Equal(t, "User-agent: *\nDisallow: /\n", rw.Body.String())
@@ -241,7 +241,7 @@ func TestBasicAuthPassword(t *testing.T) {
241
241
242 // Save the required session
242 // Save the required session
243 rw := httptest.NewRecorder()
243 rw := httptest.NewRecorder()
244− req, _ := http.NewRequest("GET", "/", nil)
244+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
245 err = proxy.sessionStore.Save(rw, req, &sessions.SessionState{
245 err = proxy.sessionStore.Save(rw, req, &sessions.SessionState{
246 Email: emailAddress,
246 Email: emailAddress,
247 })
247 })
@@ -250,7 +250,7 @@ func TestBasicAuthPassword(t *testing.T) {
250 // Extract the cookie value to inject into the test request
250 // Extract the cookie value to inject into the test request
251 cookie := rw.Header().Values("Set-Cookie")[0]
251 cookie := rw.Header().Values("Set-Cookie")[0]
252
252
253− req, _ = http.NewRequest("GET", "/", nil)
253+ req, _ = http.NewRequest(http.MethodGet, "/", nil)
254 req.Header.Set("Cookie", cookie)
254 req.Header.Set("Cookie", cookie)
255 rw = httptest.NewRecorder()
255 rw = httptest.NewRecorder()
256 proxy.ServeHTTP(rw, req)
256 proxy.ServeHTTP(rw, req)
@@ -300,14 +300,14 @@ func TestPassGroupsHeadersWithGroups(t *testing.T) {
300
300
301 // Save the required session
301 // Save the required session
302 rw := httptest.NewRecorder()
302 rw := httptest.NewRecorder()
303− req, _ := http.NewRequest("GET", "/", nil)
303+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
304 err = proxy.sessionStore.Save(rw, req, session)
304 err = proxy.sessionStore.Save(rw, req, session)
305 assert.NoError(t, err)
305 assert.NoError(t, err)
306
306
307 // Extract the cookie value to inject into the test request
307 // Extract the cookie value to inject into the test request
308 cookie := rw.Header().Values("Set-Cookie")[0]
308 cookie := rw.Header().Values("Set-Cookie")[0]
309
309
310− req, _ = http.NewRequest("GET", "/", nil)
310+ req, _ = http.NewRequest(http.MethodGet, "/", nil)
311 req.Header.Set("Cookie", cookie)
311 req.Header.Set("Cookie", cookie)
312 rw = httptest.NewRecorder()
312 rw = httptest.NewRecorder()
313 proxy.ServeHTTP(rw, req)
313 proxy.ServeHTTP(rw, req)
@@ -457,7 +457,7 @@ func (patTest *PassAccessTokenTest) getEndpointWithCookie(cookie string, endpoin
457 return 0, ""
457 return 0, ""
458 }
458 }
459
459
460− req, err := http.NewRequest("GET", endpoint, strings.NewReader(""))
460+ req, err := http.NewRequest(http.MethodGet, endpoint, strings.NewReader(""))
461 if err != nil {
461 if err != nil {
462 return 0, ""
462 return 0, ""
463 }
463 }
@@ -608,7 +608,7 @@ func NewSignInPageTest(skipProvider bool) (*SignInPageTest, error) {
608
608
609func (sipTest *SignInPageTest) GetEndpoint(endpoint string) (int, string) {
609func (sipTest *SignInPageTest) GetEndpoint(endpoint string) (int, string) {
610 rw := httptest.NewRecorder()
610 rw := httptest.NewRecorder()
611− req, _ := http.NewRequest("GET", endpoint, strings.NewReader(""))
611+ req, _ := http.NewRequest(http.MethodGet, endpoint, strings.NewReader(""))
612 sipTest.proxy.ServeHTTP(rw, req)
612 sipTest.proxy.ServeHTTP(rw, req)
613 return rw.Code, rw.Body.String()
613 return rw.Code, rw.Body.String()
614}
614}
@@ -894,7 +894,7 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts, modifiers ...OptionsModifi
894 // access_token validation.
894 // access_token validation.
895 pcTest.proxy.CookieOptions.Refresh = time.Duration(0)
895 pcTest.proxy.CookieOptions.Refresh = time.Duration(0)
896 pcTest.rw = httptest.NewRecorder()
896 pcTest.rw = httptest.NewRecorder()
897− pcTest.req, _ = http.NewRequest("GET", "/", strings.NewReader(""))
897+ pcTest.req, _ = http.NewRequest(http.MethodGet, "/", strings.NewReader(""))
898 pcTest.validateUser = true
898 pcTest.validateUser = true
899 return &pcTest, nil
899 return &pcTest, nil
900}
900}
@@ -1027,7 +1027,7 @@ func NewUserInfoEndpointTest() (*ProcessCookieTest, error) {
1027 if err != nil {
1027 if err != nil {
1028 return nil, err
1028 return nil, err
1029 }
1029 }
1030− pcTest.req, _ = http.NewRequest("GET",
1030+ pcTest.req, _ = http.NewRequest(http.MethodGet,
1031 pcTest.opts.ProxyPrefix+"/userinfo", nil)
1031 pcTest.opts.ProxyPrefix+"/userinfo", nil)
1032 return pcTest, nil
1032 return pcTest, nil
1033}
1033}
@@ -1135,7 +1135,7 @@ func NewAuthOnlyEndpointTest(querystring string, modifiers ...OptionsModifier) (
1135 return nil, err
1135 return nil, err
1136 }
1136 }
1137 pcTest.req, _ = http.NewRequest(
1137 pcTest.req, _ = http.NewRequest(
1138− "GET",
1138+ http.MethodGet,
1139 fmt.Sprintf("%s/auth%s", pcTest.opts.ProxyPrefix, querystring),
1139 fmt.Sprintf("%s/auth%s", pcTest.opts.ProxyPrefix, querystring),
1140 nil)
1140 nil)
1141 return pcTest, nil
1141 return pcTest, nil
@@ -1274,7 +1274,7 @@ func TestAuthOnlyEndpointSetXAuthRequestHeaders(t *testing.T) {
1274 pcTest.validateUser = true
1274 pcTest.validateUser = true
1275
1275
1276 pcTest.rw = httptest.NewRecorder()
1276 pcTest.rw = httptest.NewRecorder()
1277− pcTest.req, _ = http.NewRequest("GET",
1277+ pcTest.req, _ = http.NewRequest(http.MethodGet,
1278 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
1278 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
1279
1279
1280 created := time.Now()
1280 created := time.Now()
@@ -1367,7 +1367,7 @@ func TestAuthOnlyEndpointSetBasicAuthTrueRequestHeaders(t *testing.T) {
1367 pcTest.validateUser = true
1367 pcTest.validateUser = true
1368
1368
1369 pcTest.rw = httptest.NewRecorder()
1369 pcTest.rw = httptest.NewRecorder()
1370− pcTest.req, _ = http.NewRequest("GET",
1370+ pcTest.req, _ = http.NewRequest(http.MethodGet,
1371 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
1371 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
1372
1372
1373 created := time.Now()
1373 created := time.Now()
@@ -1447,7 +1447,7 @@ func TestAuthOnlyEndpointSetBasicAuthFalseRequestHeaders(t *testing.T) {
1447 pcTest.validateUser = true
1447 pcTest.validateUser = true
1448
1448
1449 pcTest.rw = httptest.NewRecorder()
1449 pcTest.rw = httptest.NewRecorder()
1450− pcTest.req, _ = http.NewRequest("GET",
1450+ pcTest.req, _ = http.NewRequest(http.MethodGet,
1451 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
1451 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
1452
1452
1453 created := time.Now()
1453 created := time.Now()
@@ -1495,7 +1495,7 @@ func TestAuthSkippedForPreflightRequests(t *testing.T) {
1495 }
1495 }
1496 proxy.provider = NewTestProvider(upstreamURL, "")
1496 proxy.provider = NewTestProvider(upstreamURL, "")
1497 rw := httptest.NewRecorder()
1497 rw := httptest.NewRecorder()
1498− req, _ := http.NewRequest("OPTIONS", "/preflight-request", nil)
1498+ req, _ := http.NewRequest(http.MethodOptions, "/preflight-request", nil)
1499 proxy.ServeHTTP(rw, req)
1499 proxy.ServeHTTP(rw, req)
1500
1500
1501 assert.Equal(t, 200, rw.Code)
1501 assert.Equal(t, 200, rw.Code)
@@ -1652,19 +1652,19 @@ func TestRequestSignature(t *testing.T) {
1652 resp string
1652 resp string
1653 }{
1653 }{
1654 "No request signature": {
1654 "No request signature": {
1655− method: "GET",
1655+ method: http.MethodGet,
1656 body: "",
1656 body: "",
1657 key: "",
1657 key: "",
1658 resp: "no signature received",
1658 resp: "no signature received",
1659 },
1659 },
1660 "Get request": {
1660 "Get request": {
1661− method: "GET",
1661+ method: http.MethodGet,
1662 body: "",
1662 body: "",
1663 key: "7d9e1aa87a5954e6f9fc59266b3af9d7c35fda2d",
1663 key: "7d9e1aa87a5954e6f9fc59266b3af9d7c35fda2d",
1664 resp: "signatures match",
1664 resp: "signatures match",
1665 },
1665 },
1666 "Post request": {
1666 "Post request": {
1667− method: "POST",
1667+ method: http.MethodPost,
1668 body: `{ "hello": "world!" }`,
1668 body: `{ "hello": "world!" }`,
1669 key: "d90df39e2d19282840252612dd7c81421a372f61",
1669 key: "d90df39e2d19282840252612dd7c81421a372f61",
1670 resp: "signatures match",
1670 resp: "signatures match",
@@ -2189,7 +2189,7 @@ func TestTrustedIPs(t *testing.T) {
2189 reverseProxy: false,
2189 reverseProxy: false,
2190 realClientIPHeader: "X-Real-IP", // Default value
2190 realClientIPHeader: "X-Real-IP", // Default value
2191 req: func() *http.Request {
2191 req: func() *http.Request {
2192− req, _ := http.NewRequest("GET", "/", nil)
2192+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
2193 return req
2193 return req
2194 }(),
2194 }(),
2195 expectTrusted: false,
2195 expectTrusted: false,
@@ -2201,7 +2201,7 @@ func TestTrustedIPs(t *testing.T) {
2201 reverseProxy: false,
2201 reverseProxy: false,
2202 realClientIPHeader: "X-Real-IP",
2202 realClientIPHeader: "X-Real-IP",
2203 req: func() *http.Request {
2203 req: func() *http.Request {
2204− req, _ := http.NewRequest("GET", "/", nil)
2204+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
2205 req.RemoteAddr = "@"
2205 req.RemoteAddr = "@"
2206 return req
2206 return req
2207 }(),
2207 }(),
@@ -2214,7 +2214,7 @@ func TestTrustedIPs(t *testing.T) {
2214 reverseProxy: false,
2214 reverseProxy: false,
2215 realClientIPHeader: "X-Real-IP",
2215 realClientIPHeader: "X-Real-IP",
2216 req: func() *http.Request {
2216 req: func() *http.Request {
2217− req, _ := http.NewRequest("GET", "/", nil)
2217+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
2218 req.RemoteAddr = "@"
2218 req.RemoteAddr = "@"
2219 return req
2219 return req
2220 }(),
2220 }(),
@@ -2227,7 +2227,7 @@ func TestTrustedIPs(t *testing.T) {
2227 reverseProxy: false,
2227 reverseProxy: false,
2228 realClientIPHeader: "X-Real-IP", // Default value
2228 realClientIPHeader: "X-Real-IP", // Default value
2229 req: func() *http.Request {
2229 req: func() *http.Request {
2230− req, _ := http.NewRequest("GET", "/", nil)
2230+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
2231 req.RemoteAddr = "127.0.0.1:43670"
2231 req.RemoteAddr = "127.0.0.1:43670"
2232 return req
2232 return req
2233 }(),
2233 }(),
@@ -2240,7 +2240,7 @@ func TestTrustedIPs(t *testing.T) {
2240 reverseProxy: true,
2240 reverseProxy: true,
2241 realClientIPHeader: "X-Real-IP", // Default value
2241 realClientIPHeader: "X-Real-IP", // Default value
2242 req: func() *http.Request {
2242 req: func() *http.Request {
2243− req, _ := http.NewRequest("GET", "/", nil)
2243+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
2244 req.RemoteAddr = "127.0.0.1:44324"
2244 req.RemoteAddr = "127.0.0.1:44324"
2245 return req
2245 return req
2246 }(),
2246 }(),
@@ -2253,7 +2253,7 @@ func TestTrustedIPs(t *testing.T) {
2253 reverseProxy: true,
2253 reverseProxy: true,
2254 realClientIPHeader: "X-Forwarded-For",
2254 realClientIPHeader: "X-Forwarded-For",
2255 req: func() *http.Request {
2255 req: func() *http.Request {
2256− req, _ := http.NewRequest("GET", "/", nil)
2256+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
2257 req.Header.Add("X-Forwarded-For", "127.0.0.1")
2257 req.Header.Add("X-Forwarded-For", "127.0.0.1")
2258 return req
2258 return req
2259 }(),
2259 }(),
@@ -2266,7 +2266,7 @@ func TestTrustedIPs(t *testing.T) {
2266 reverseProxy: true,
2266 reverseProxy: true,
2267 realClientIPHeader: "X-Forwarded-For",
2267 realClientIPHeader: "X-Forwarded-For",
2268 req: func() *http.Request {
2268 req: func() *http.Request {
2269− req, _ := http.NewRequest("GET", "/", nil)
2269+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
2270 req.Header.Add("X-Forwarded-For", "::1")
2270 req.Header.Add("X-Forwarded-For", "::1")
2271 return req
2271 return req
2272 }(),
2272 }(),
@@ -2279,7 +2279,7 @@ func TestTrustedIPs(t *testing.T) {
2279 reverseProxy: true,
2279 reverseProxy: true,
2280 realClientIPHeader: "X-Forwarded-For",
2280 realClientIPHeader: "X-Forwarded-For",
2281 req: func() *http.Request {
2281 req: func() *http.Request {
2282− req, _ := http.NewRequest("GET", "/", nil)
2282+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
2283 req.Header.Add("X-Forwarded-For", "12.34.56.78")
2283 req.Header.Add("X-Forwarded-For", "12.34.56.78")
2284 return req
2284 return req
2285 }(),
2285 }(),
@@ -2292,7 +2292,7 @@ func TestTrustedIPs(t *testing.T) {
2292 reverseProxy: true,
2292 reverseProxy: true,
2293 realClientIPHeader: "X-Forwarded-For",
2293 realClientIPHeader: "X-Forwarded-For",
2294 req: func() *http.Request {
2294 req: func() *http.Request {
2295− req, _ := http.NewRequest("GET", "/", nil)
2295+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
2296 req.Header.Add("X-Forwarded-For", "::2")
2296 req.Header.Add("X-Forwarded-For", "::2")
2297 return req
2297 return req
2298 }(),
2298 }(),
@@ -2305,7 +2305,7 @@ func TestTrustedIPs(t *testing.T) {
2305 reverseProxy: true,
2305 reverseProxy: true,
2306 realClientIPHeader: "X-Forwarded-For",
2306 realClientIPHeader: "X-Forwarded-For",
2307 req: func() *http.Request {
2307 req: func() *http.Request {
2308− req, _ := http.NewRequest("GET", "/", nil)
2308+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
2309 req.Header.Add("X-Real-IP", "::1")
2309 req.Header.Add("X-Real-IP", "::1")
2310 return req
2310 return req
2311 }(),
2311 }(),
@@ -2318,7 +2318,7 @@ func TestTrustedIPs(t *testing.T) {
2318 reverseProxy: true,
2318 reverseProxy: true,
2319 realClientIPHeader: "X-Forwarded-For",
2319 realClientIPHeader: "X-Forwarded-For",
2320 req: func() *http.Request {
2320 req: func() *http.Request {
2321− req, _ := http.NewRequest("GET", "/", nil)
2321+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
2322 req.Header.Add("X-Forwarded-For", "adsfljk29242as!!")
2322 req.Header.Add("X-Forwarded-For", "adsfljk29242as!!")
2323 return req
2323 return req
2324 }(),
2324 }(),
@@ -2331,7 +2331,7 @@ func TestTrustedIPs(t *testing.T) {
2331 reverseProxy: false,
2331 reverseProxy: false,
2332 realClientIPHeader: "X-Real-IP",
2332 realClientIPHeader: "X-Real-IP",
2333 req: func() *http.Request {
2333 req: func() *http.Request {
2334− req, _ := http.NewRequest("GET", "/", nil)
2334+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
2335 req.RemoteAddr = "adsfljk29242as!!"
2335 req.RemoteAddr = "adsfljk29242as!!"
2336 return req
2336 return req
2337 }(),
2337 }(),
@@ -2427,12 +2427,12 @@ func Test_buildRoutesAllowlist(t *testing.T) {
2427 },
2427 },
2428 expectedRoutes: []expectedAllowedRoute{
2428 expectedRoutes: []expectedAllowedRoute{
2429 {
2429 {
2430− method: "GET",
2430+ method: http.MethodGet,
2431 negate: false,
2431 negate: false,
2432 regexString: "^/foo/bar",
2432 regexString: "^/foo/bar",
2433 },
2433 },
2434 {
2434 {
2435− method: "POST",
2435+ method: http.MethodPost,
2436 negate: false,
2436 negate: false,
2437 regexString: "^/baz/[0-9]+/thing",
2437 regexString: "^/baz/[0-9]+/thing",
2438 },
2438 },
@@ -2485,11 +2485,11 @@ func Test_buildRoutesAllowlist(t *testing.T) {
2485 regexString: "^/baz/[0-9]+/thing/regex",
2485 regexString: "^/baz/[0-9]+/thing/regex",
2486 },
2486 },
2487 {
2487 {
2488− method: "GET",
2488+ method: http.MethodGet,
2489 regexString: "^/foo/bar",
2489 regexString: "^/foo/bar",
2490 },
2490 },
2491 {
2491 {
2492− method: "POST",
2492+ method: http.MethodPost,
2493 regexString: "^/baz/[0-9]+/thing",
2493 regexString: "^/baz/[0-9]+/thing",
2494 },
2494 },
2495 {
2495 {
@@ -2641,7 +2641,7 @@ func TestApiRoutes(t *testing.T) {
2641
2641
2642 for _, tc := range testCases {
2642 for _, tc := range testCases {
2643 t.Run(tc.name, func(t *testing.T) {
2643 t.Run(tc.name, func(t *testing.T) {
2644− req, err := http.NewRequest("GET", tc.url, nil)
2644+ req, err := http.NewRequest(http.MethodGet, tc.url, nil)
2645 req.Header.Set("Accept", tc.contentType)
2645 req.Header.Set("Accept", tc.contentType)
2646 assert.NoError(t, err)
2646 assert.NoError(t, err)
2647
2647
@@ -2700,37 +2700,37 @@ func TestAllowedRequest(t *testing.T) {
2700 }{
2700 }{
2701 {
2701 {
2702 name: "Regex GET allowed",
2702 name: "Regex GET allowed",
2703− method: "GET",
2703+ method: http.MethodGet,
2704 url: "/skip/auth/regex",
2704 url: "/skip/auth/regex",
2705 allowed: true,
2705 allowed: true,
2706 },
2706 },
2707 {
2707 {
2708 name: "Regex POST allowed ",
2708 name: "Regex POST allowed ",
2709− method: "POST",
2709+ method: http.MethodPost,
2710 url: "/skip/auth/regex",
2710 url: "/skip/auth/regex",
2711 allowed: true,
2711 allowed: true,
2712 },
2712 },
2713 {
2713 {
2714 name: "Regex denied",
2714 name: "Regex denied",
2715− method: "GET",
2715+ method: http.MethodGet,
2716 url: "/wrong/denied",
2716 url: "/wrong/denied",
2717 allowed: false,
2717 allowed: false,
2718 },
2718 },
2719 {
2719 {
2720 name: "Regex allowed with fragment-free path",
2720 name: "Regex allowed with fragment-free path",
2721− method: "GET",
2721+ method: http.MethodGet,
2722 url: "/public/legit/endpoint",
2722 url: "/public/legit/endpoint",
2723 allowed: true,
2723 allowed: true,
2724 },
2724 },
2725 {
2725 {
2726 name: "Regex denied when path contains encoded fragment suffix",
2726 name: "Regex denied when path contains encoded fragment suffix",
2727− method: "GET",
2727+ method: http.MethodGet,
2728 url: "/public/secret%23/endpoint",
2728 url: "/public/secret%23/endpoint",
2729 allowed: false,
2729 allowed: false,
2730 },
2730 },
2731 {
2731 {
2732 name: "Route allowed",
2732 name: "Route allowed",
2733− method: "GET",
2733+ method: http.MethodGet,
2734 url: "/skip/auth/routes/get",
2734 url: "/skip/auth/routes/get",
2735 allowed: true,
2735 allowed: true,
2736 },
2736 },
@@ -2742,25 +2742,25 @@ func TestAllowedRequest(t *testing.T) {
2742 },
2742 },
2743 {
2743 {
2744 name: "Route denied with wrong path",
2744 name: "Route denied with wrong path",
2745− method: "GET",
2745+ method: http.MethodGet,
2746 url: "/skip/auth/routes/wrong/path",
2746 url: "/skip/auth/routes/wrong/path",
2747 allowed: false,
2747 allowed: false,
2748 },
2748 },
2749 {
2749 {
2750 name: "Route denied with wrong path and method",
2750 name: "Route denied with wrong path and method",
2751− method: "POST",
2751+ method: http.MethodPost,
2752 url: "/skip/auth/routes/wrong/path",
2752 url: "/skip/auth/routes/wrong/path",
2753 allowed: false,
2753 allowed: false,
2754 },
2754 },
2755 {
2755 {
2756 name: "Route allowed with fragment-free path",
2756 name: "Route allowed with fragment-free path",
2757− method: "GET",
2757+ method: http.MethodGet,
2758 url: "/foo/public/bar",
2758 url: "/foo/public/bar",
2759 allowed: true,
2759 allowed: true,
2760 },
2760 },
2761 {
2761 {
2762 name: "Route denied when path contains encoded fragment suffix",
2762 name: "Route denied when path contains encoded fragment suffix",
2763− method: "GET",
2763+ method: http.MethodGet,
2764 url: "/foo/secret%23/bar",
2764 url: "/foo/secret%23/bar",
2765 allowed: false,
2765 allowed: false,
2766 },
2766 },
@@ -2825,37 +2825,37 @@ func TestAllowedRequestWithForwardedUriHeader(t *testing.T) {
2825 }{
2825 }{
2826 {
2826 {
2827 name: "Regex GET allowed",
2827 name: "Regex GET allowed",
2828− method: "GET",
2828+ method: http.MethodGet,
2829 url: "/skip/auth/regex",
2829 url: "/skip/auth/regex",
2830 allowed: true,
2830 allowed: true,
2831 },
2831 },
2832 {
2832 {
2833 name: "Regex POST allowed ",
2833 name: "Regex POST allowed ",
2834− method: "POST",
2834+ method: http.MethodPost,
2835 url: "/skip/auth/regex",
2835 url: "/skip/auth/regex",
2836 allowed: true,
2836 allowed: true,
2837 },
2837 },
2838 {
2838 {
2839 name: "Regex denied",
2839 name: "Regex denied",
2840− method: "GET",
2840+ method: http.MethodGet,
2841 url: "/wrong/denied",
2841 url: "/wrong/denied",
2842 allowed: false,
2842 allowed: false,
2843 },
2843 },
2844 {
2844 {
2845 name: "Regex allowed with fragment-free path",
2845 name: "Regex allowed with fragment-free path",
2846− method: "GET",
2846+ method: http.MethodGet,
2847 url: "/public/legit/endpoint",
2847 url: "/public/legit/endpoint",
2848 allowed: true,
2848 allowed: true,
2849 },
2849 },
2850 {
2850 {
2851 name: "Regex denied when X-Forwarded-Uri contains an encoded fragment suffix",
2851 name: "Regex denied when X-Forwarded-Uri contains an encoded fragment suffix",
2852− method: "GET",
2852+ method: http.MethodGet,
2853 url: "/public/secret%23/endpoint",
2853 url: "/public/secret%23/endpoint",
2854 allowed: false,
2854 allowed: false,
2855 },
2855 },
2856 {
2856 {
2857 name: "Route allowed",
2857 name: "Route allowed",
2858− method: "GET",
2858+ method: http.MethodGet,
2859 url: "/skip/auth/routes/get",
2859 url: "/skip/auth/routes/get",
2860 allowed: true,
2860 allowed: true,
2861 },
2861 },
@@ -2867,25 +2867,25 @@ func TestAllowedRequestWithForwardedUriHeader(t *testing.T) {
2867 },
2867 },
2868 {
2868 {
2869 name: "Route denied with wrong path",
2869 name: "Route denied with wrong path",
2870− method: "GET",
2870+ method: http.MethodGet,
2871 url: "/skip/auth/routes/wrong/path",
2871 url: "/skip/auth/routes/wrong/path",
2872 allowed: false,
2872 allowed: false,
2873 },
2873 },
2874 {
2874 {
2875 name: "Route denied with wrong path and method",
2875 name: "Route denied with wrong path and method",
2876− method: "POST",
2876+ method: http.MethodPost,
2877 url: "/skip/auth/routes/wrong/path",
2877 url: "/skip/auth/routes/wrong/path",
2878 allowed: false,
2878 allowed: false,
2879 },
2879 },
2880 {
2880 {
2881 name: "Route allowed with fragment-free path",
2881 name: "Route allowed with fragment-free path",
2882− method: "GET",
2882+ method: http.MethodGet,
2883 url: "/foo/public/bar",
2883 url: "/foo/public/bar",
2884 allowed: true,
2884 allowed: true,
2885 },
2885 },
2886 {
2886 {
2887 name: "Route denied when X-Forwarded-Uri contains an encoded fragment suffix",
2887 name: "Route denied when X-Forwarded-Uri contains an encoded fragment suffix",
2888− method: "GET",
2888+ method: http.MethodGet,
2889 url: "/foo/secret%23/bar",
2889 url: "/foo/secret%23/bar",
2890 allowed: false,
2890 allowed: false,
2891 },
2891 },
@@ -2986,37 +2986,37 @@ func TestAllowedRequestNegateWithoutMethod(t *testing.T) {
2986 }{
2986 }{
2987 {
2987 {
2988 name: "Some static file allowed",
2988 name: "Some static file allowed",
2989− method: "GET",
2989+ method: http.MethodGet,
2990 url: "/static/file.txt",
2990 url: "/static/file.txt",
2991 allowed: true,
2991 allowed: true,
2992 },
2992 },
2993 {
2993 {
2994 name: "POST to contact form allowed",
2994 name: "POST to contact form allowed",
2995− method: "POST",
2995+ method: http.MethodPost,
2996 url: "/contact",
2996 url: "/contact",
2997 allowed: true,
2997 allowed: true,
2998 },
2998 },
2999 {
2999 {
3000 name: "Regex POST allowed",
3000 name: "Regex POST allowed",
3001− method: "POST",
3001+ method: http.MethodPost,
3002 url: "/api/public-entity",
3002 url: "/api/public-entity",
3003 allowed: true,
3003 allowed: true,
3004 },
3004 },
3005 {
3005 {
3006 name: "Regex POST with trailing slash allowed",
3006 name: "Regex POST with trailing slash allowed",
3007− method: "POST",
3007+ method: http.MethodPost,
3008 url: "/api/public-entity/",
3008 url: "/api/public-entity/",
3009 allowed: true,
3009 allowed: true,
3010 },
3010 },
3011 {
3011 {
3012 name: "Regex GET api route denied",
3012 name: "Regex GET api route denied",
3013− method: "GET",
3013+ method: http.MethodGet,
3014 url: "/api/users",
3014 url: "/api/users",
3015 allowed: false,
3015 allowed: false,
3016 },
3016 },
3017 {
3017 {
3018 name: "Regex POST api route denied",
3018 name: "Regex POST api route denied",
3019− method: "POST",
3019+ method: http.MethodPost,
3020 url: "/api/users",
3020 url: "/api/users",
3021 allowed: false,
3021 allowed: false,
3022 },
3022 },
@@ -3086,37 +3086,37 @@ func TestAllowedRequestNegateWithMethod(t *testing.T) {
3086 }{
3086 }{
3087 {
3087 {
3088 name: "Some static file allowed",
3088 name: "Some static file allowed",
3089− method: "GET",
3089+ method: http.MethodGet,
3090 url: "/static/file.txt",
3090 url: "/static/file.txt",
3091 allowed: true,
3091 allowed: true,
3092 },
3092 },
3093 {
3093 {
3094 name: "POST to contact form not allowed",
3094 name: "POST to contact form not allowed",
3095− method: "POST",
3095+ method: http.MethodPost,
3096 url: "/contact",
3096 url: "/contact",
3097 allowed: false,
3097 allowed: false,
3098 },
3098 },
3099 {
3099 {
3100 name: "Regex POST allowed",
3100 name: "Regex POST allowed",
3101− method: "POST",
3101+ method: http.MethodPost,
3102 url: "/api/public-entity",
3102 url: "/api/public-entity",
3103 allowed: true,
3103 allowed: true,
3104 },
3104 },
3105 {
3105 {
3106 name: "Regex POST with trailing slash allowed",
3106 name: "Regex POST with trailing slash allowed",
3107− method: "POST",
3107+ method: http.MethodPost,
3108 url: "/api/public-entity/",
3108 url: "/api/public-entity/",
3109 allowed: true,
3109 allowed: true,
3110 },
3110 },
3111 {
3111 {
3112 name: "Regex GET api route denied",
3112 name: "Regex GET api route denied",
3113− method: "GET",
3113+ method: http.MethodGet,
3114 url: "/api/users",
3114 url: "/api/users",
3115 allowed: false,
3115 allowed: false,
3116 },
3116 },
3117 {
3117 {
3118 name: "Regex POST api route denied",
3118 name: "Regex POST api route denied",
3119− method: "POST",
3119+ method: http.MethodPost,
3120 url: "/api/users",
3120 url: "/api/users",
3121 allowed: false,
3121 allowed: false,
3122 },
3122 },
@@ -3256,7 +3256,7 @@ func TestProxyAllowedGroups(t *testing.T) {
3256 t.Fatal(err)
3256 t.Fatal(err)
3257 }
3257 }
3258
3258
3259− test.req, _ = http.NewRequest("GET", fmt.Sprintf("/%s", tt.querystring), nil)
3259+ test.req, _ = http.NewRequest(http.MethodGet, fmt.Sprintf("/%s", tt.querystring), nil)
3260
3260
3261 test.req.Header.Add("accept", applicationJSON)
3261 test.req.Header.Add("accept", applicationJSON)
3262 err = test.SaveSession(session)
3262 err = test.SaveSession(session)
@@ -3400,7 +3400,7 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
3400 {
3400 {
3401 name: "UserWithGroupSkipAuthPreflight",
3401 name: "UserWithGroupSkipAuthPreflight",
3402 groups: []string{"a", "c"},
3402 groups: []string{"a", "c"},
3403− method: "OPTIONS",
3403+ method: http.MethodOptions,
3404 ip: "1.2.3.5:43670",
3404 ip: "1.2.3.5:43670",
3405 withSession: true,
3405 withSession: true,
3406 expectedStatusCode: http.StatusAccepted,
3406 expectedStatusCode: http.StatusAccepted,
@@ -3408,7 +3408,7 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
3408 {
3408 {
3409 name: "UserWithGroupTrustedIp",
3409 name: "UserWithGroupTrustedIp",
3410 groups: []string{"a", "c"},
3410 groups: []string{"a", "c"},
3411− method: "GET",
3411+ method: http.MethodGet,
3412 ip: "1.2.3.4:43670",
3412 ip: "1.2.3.4:43670",
3413 withSession: true,
3413 withSession: true,
3414 expectedStatusCode: http.StatusAccepted,
3414 expectedStatusCode: http.StatusAccepted,
@@ -3416,7 +3416,7 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
3416 {
3416 {
3417 name: "UserWithoutGroupSkipAuthPreflight",
3417 name: "UserWithoutGroupSkipAuthPreflight",
3418 groups: []string{"c"},
3418 groups: []string{"c"},
3419− method: "OPTIONS",
3419+ method: http.MethodOptions,
3420 ip: "1.2.3.5:43670",
3420 ip: "1.2.3.5:43670",
3421 withSession: true,
3421 withSession: true,
3422 expectedStatusCode: http.StatusForbidden,
3422 expectedStatusCode: http.StatusForbidden,
@@ -3424,21 +3424,21 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
3424 {
3424 {
3425 name: "UserWithoutGroupTrustedIp",
3425 name: "UserWithoutGroupTrustedIp",
3426 groups: []string{"c"},
3426 groups: []string{"c"},
3427− method: "GET",
3427+ method: http.MethodGet,
3428 ip: "1.2.3.4:43670",
3428 ip: "1.2.3.4:43670",
3429 withSession: true,
3429 withSession: true,
3430 expectedStatusCode: http.StatusForbidden,
3430 expectedStatusCode: http.StatusForbidden,
3431 },
3431 },
3432 {
3432 {
3433 name: "UserWithoutSessionSkipAuthPreflight",
3433 name: "UserWithoutSessionSkipAuthPreflight",
3434− method: "OPTIONS",
3434+ method: http.MethodOptions,
3435 ip: "1.2.3.5:43670",
3435 ip: "1.2.3.5:43670",
3436 withSession: false,
3436 withSession: false,
3437 expectedStatusCode: http.StatusAccepted,
3437 expectedStatusCode: http.StatusAccepted,
3438 },
3438 },
3439 {
3439 {
3440 name: "UserWithoutSessionTrustedIp",
3440 name: "UserWithoutSessionTrustedIp",
3441− method: "GET",
3441+ method: http.MethodGet,
3442 ip: "1.2.3.4:43670",
3442 ip: "1.2.3.4:43670",
3443 withSession: false,
3443 withSession: false,
3444 expectedStatusCode: http.StatusAccepted,
3444 expectedStatusCode: http.StatusAccepted,
@@ -3790,14 +3790,14 @@ func TestIdTokenPlaceholderInSignOut(t *testing.T) {
3790
3790
3791 // Save the required session
3791 // Save the required session
3792 rw := httptest.NewRecorder()
3792 rw := httptest.NewRecorder()
3793− req, _ := http.NewRequest("GET", "/", nil)
3793+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
3794 err = proxy.sessionStore.Save(rw, req, session)
3794 err = proxy.sessionStore.Save(rw, req, session)
3795 assert.NoError(t, err)
3795 assert.NoError(t, err)
3796
3796
3797 rw = httptest.NewRecorder()
3797 rw = httptest.NewRecorder()
3798
3798
3799 rdUrl := url.QueryEscape("https://my-oidc-provider.example.com/sign_out_page?id_token_hint={id_token}&post_logout_redirect_uri=https://my-app.example.com/")
3799 rdUrl := url.QueryEscape("https://my-oidc-provider.example.com/sign_out_page?id_token_hint={id_token}&post_logout_redirect_uri=https://my-app.example.com/")
3800− req, _ = http.NewRequest("GET", "/oauth2/sign_out?rd="+rdUrl, nil)
3800+ req, _ = http.NewRequest(http.MethodGet, "/oauth2/sign_out?rd="+rdUrl, nil)
3801 req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{
3801 req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{
3802 RequestID: "11111111-2222-4333-8444-555555555555",
3802 RequestID: "11111111-2222-4333-8444-555555555555",
3803 Session: session,
3803 Session: session,
pkg/apis/options/load.go+1−1
@@ -145,7 +145,7 @@ func loadAndSubstituteEnvs(configFileName string) ([]byte, error) {
145func registerFlags(v *viper.Viper, prefix string, flagSet *pflag.FlagSet, options interface{}) error {
145func registerFlags(v *viper.Viper, prefix string, flagSet *pflag.FlagSet, options interface{}) error {
146 val := reflect.ValueOf(options)
146 val := reflect.ValueOf(options)
147 var typ reflect.Type
147 var typ reflect.Type
148− if val.Kind() == reflect.Ptr {
148+ if val.Kind() == reflect.Pointer {
149 typ = val.Elem().Type()
149 typ = val.Elem().Type()
150 } else {
150 } else {
151 typ = val.Type()
151 typ = val.Type()
pkg/authentication/hmacauth/hmacauth_test.go+1−1
@@ -286,7 +286,7 @@ func TestSendAuthenticatedPostRequestToServer(t *testing.T) {
286 upstream := httptest.NewServer(
286 upstream := httptest.NewServer(
287 http.HandlerFunc(authenticator.Authenticate))
287 http.HandlerFunc(authenticator.Authenticate))
288
288
289− req, err := http.NewRequest("POST", upstream.URL+"/foo/bar",
289+ req, err := http.NewRequest(http.MethodPost, upstream.URL+"/foo/bar",
290 io.NopCloser(&fakeNetConn{reqBody: payload}))
290 io.NopCloser(&fakeNetConn{reqBody: payload}))
291 if err != nil {
291 if err != nil {
292 panic(err)
292 panic(err)
pkg/requests/builder_test.go+15−15
@@ -31,7 +31,7 @@ var _ = Describe("Builder suite", func() {
31
31
32 Context("with a basic request", func() {
32 Context("with a basic request", func() {
33 assertSuccessfulRequest(getBuilder, testHTTPRequest{
33 assertSuccessfulRequest(getBuilder, testHTTPRequest{
34− Method: "GET",
34+ Method: http.MethodGet,
35 Header: baseHeaders,
35 Header: baseHeaders,
36 Body: []byte{},
36 Body: []byte{},
37 RequestURI: "/json/path",
37 RequestURI: "/json/path",
@@ -52,7 +52,7 @@ var _ = Describe("Builder suite", func() {
52 })
52 })
53
53
54 assertSuccessfulRequest(getBuilder, testHTTPRequest{
54 assertSuccessfulRequest(getBuilder, testHTTPRequest{
55− Method: "GET",
55+ Method: http.MethodGet,
56 Header: baseHeaders,
56 Header: baseHeaders,
57 Body: []byte{},
57 Body: []byte{},
58 RequestURI: "/json/path",
58 RequestURI: "/json/path",
@@ -78,7 +78,7 @@ var _ = Describe("Builder suite", func() {
78 })
78 })
79
79
80 assertSuccessfulRequest(getBuilder, testHTTPRequest{
80 assertSuccessfulRequest(getBuilder, testHTTPRequest{
81− Method: "GET",
81+ Method: http.MethodGet,
82 Header: header,
82 Header: header,
83 Body: []byte(body),
83 Body: []byte(body),
84 RequestURI: "/json/path",
84 RequestURI: "/json/path",
@@ -93,11 +93,11 @@ var _ = Describe("Builder suite", func() {
93
93
94 BeforeEach(func() {
94 BeforeEach(func() {
95 buf := bytes.NewBuffer([]byte(body))
95 buf := bytes.NewBuffer([]byte(body))
96− b = b.WithMethod("POST").WithBody(buf)
96+ b = b.WithMethod(http.MethodPost).WithBody(buf)
97 })
97 })
98
98
99 assertSuccessfulRequest(getBuilder, testHTTPRequest{
99 assertSuccessfulRequest(getBuilder, testHTTPRequest{
100− Method: "POST",
100+ Method: http.MethodPost,
101 Header: header,
101 Header: header,
102 Body: []byte(body),
102 Body: []byte(body),
103 RequestURI: "/json/path",
103 RequestURI: "/json/path",
@@ -109,11 +109,11 @@ var _ = Describe("Builder suite", func() {
109 header.Set("Content-Length", "0")
109 header.Set("Content-Length", "0")
110
110
111 BeforeEach(func() {
111 BeforeEach(func() {
112− b = b.WithMethod("POST")
112+ b = b.WithMethod(http.MethodPost)
113 })
113 })
114
114
115 assertSuccessfulRequest(getBuilder, testHTTPRequest{
115 assertSuccessfulRequest(getBuilder, testHTTPRequest{
116− Method: "POST",
116+ Method: http.MethodPost,
117 Header: header,
117 Header: header,
118 Body: []byte{},
118 Body: []byte{},
119 RequestURI: "/json/path",
119 RequestURI: "/json/path",
@@ -122,11 +122,11 @@ var _ = Describe("Builder suite", func() {
122
122
123 Context("OPTIONS", func() {
123 Context("OPTIONS", func() {
124 BeforeEach(func() {
124 BeforeEach(func() {
125− b = b.WithMethod("OPTIONS")
125+ b = b.WithMethod(http.MethodOptions)
126 })
126 })
127
127
128 assertSuccessfulRequest(getBuilder, testHTTPRequest{
128 assertSuccessfulRequest(getBuilder, testHTTPRequest{
129− Method: "OPTIONS",
129+ Method: http.MethodOptions,
130 Header: baseHeaders,
130 Header: baseHeaders,
131 Body: []byte{},
131 Body: []byte{},
132 RequestURI: "/json/path",
132 RequestURI: "/json/path",
@@ -152,7 +152,7 @@ var _ = Describe("Builder suite", func() {
152 })
152 })
153
153
154 assertSuccessfulRequest(getBuilder, testHTTPRequest{
154 assertSuccessfulRequest(getBuilder, testHTTPRequest{
155− Method: "GET",
155+ Method: http.MethodGet,
156 Header: header,
156 Header: header,
157 Body: []byte{},
157 Body: []byte{},
158 RequestURI: "/json/path",
158 RequestURI: "/json/path",
@@ -170,7 +170,7 @@ var _ = Describe("Builder suite", func() {
170 })
170 })
171
171
172 assertSuccessfulRequest(getBuilder, testHTTPRequest{
172 assertSuccessfulRequest(getBuilder, testHTTPRequest{
173− Method: "GET",
173+ Method: http.MethodGet,
174 Header: replacementHeaders,
174 Header: replacementHeaders,
175 Body: []byte{},
175 Body: []byte{},
176 RequestURI: "/json/path",
176 RequestURI: "/json/path",
@@ -190,7 +190,7 @@ var _ = Describe("Builder suite", func() {
190 })
190 })
191
191
192 assertSuccessfulRequest(getBuilder, testHTTPRequest{
192 assertSuccessfulRequest(getBuilder, testHTTPRequest{
193− Method: "GET",
193+ Method: http.MethodGet,
194 Header: replacementHeaders,
194 Header: replacementHeaders,
195 Body: []byte{},
195 Body: []byte{},
196 RequestURI: "/json/path",
196 RequestURI: "/json/path",
@@ -205,7 +205,7 @@ var _ = Describe("Builder suite", func() {
205 })
205 })
206
206
207 assertSuccessfulRequest(getBuilder, testHTTPRequest{
207 assertSuccessfulRequest(getBuilder, testHTTPRequest{
208− Method: "GET",
208+ Method: http.MethodGet,
209 Header: header,
209 Header: header,
210 Body: []byte{},
210 Body: []byte{},
211 RequestURI: "/json/path",
211 RequestURI: "/json/path",
@@ -219,12 +219,12 @@ var _ = Describe("Builder suite", func() {
219 result := b.Do()
219 result := b.Do()
220 Expect(result.Error()).ToNot(HaveOccurred())
220 Expect(result.Error()).ToNot(HaveOccurred())
221
221
222− b.WithMethod("POST")
222+ b.WithMethod(http.MethodPost)
223 })
223 })
224
224
225 Context("should not redo the request", func() {
225 Context("should not redo the request", func() {
226 assertSuccessfulRequest(getBuilder, testHTTPRequest{
226 assertSuccessfulRequest(getBuilder, testHTTPRequest{
227− Method: "GET",
227+ Method: http.MethodGet,
228 Header: baseHeaders,
228 Header: baseHeaders,
229 Body: []byte{},
229 Body: []byte{},
230 RequestURI: "/json/path",
230 RequestURI: "/json/path",
providers/azure.go+2−2
@@ -166,7 +166,7 @@ func (p *AzureProvider) Redeem(ctx context.Context, redirectURL, code, codeVerif
166
166
167 err = requests.New(p.RedeemURL.String()).
167 err = requests.New(p.RedeemURL.String()).
168 WithContext(ctx).
168 WithContext(ctx).
169− WithMethod("POST").
169+ WithMethod(http.MethodPost).
170 WithBody(bytes.NewBufferString(params.Encode())).
170 WithBody(bytes.NewBufferString(params.Encode())).
171 SetHeader("Content-Type", "application/x-www-form-urlencoded").
171 SetHeader("Content-Type", "application/x-www-form-urlencoded").
172 Do().
172 Do().
@@ -334,7 +334,7 @@ func (p *AzureProvider) redeemRefreshToken(ctx context.Context, s *sessions.Sess
334
334
335 err = requests.New(p.RedeemURL.String()).
335 err = requests.New(p.RedeemURL.String()).
336 WithContext(ctx).
336 WithContext(ctx).
337− WithMethod("POST").
337+ WithMethod(http.MethodPost).
338 WithBody(bytes.NewBufferString(params.Encode())).
338 WithBody(bytes.NewBufferString(params.Encode())).
339 SetHeader("Content-Type", "application/x-www-form-urlencoded").
339 SetHeader("Content-Type", "application/x-www-form-urlencoded").
340 Do().
340 Do().
providers/google.go+2−2
@@ -219,7 +219,7 @@ func (p *GoogleProvider) Redeem(ctx context.Context, redirectURL, code, codeVeri
219
219
220 err = requests.New(p.RedeemURL.String()).
220 err = requests.New(p.RedeemURL.String()).
221 WithContext(ctx).
221 WithContext(ctx).
222− WithMethod("POST").
222+ WithMethod(http.MethodPost).
223 WithBody(bytes.NewBufferString(params.Encode())).
223 WithBody(bytes.NewBufferString(params.Encode())).
224 SetHeader("Content-Type", "application/x-www-form-urlencoded").
224 SetHeader("Content-Type", "application/x-www-form-urlencoded").
225 Do().
225 Do().
@@ -543,7 +543,7 @@ func (p *GoogleProvider) redeemRefreshToken(ctx context.Context, s *sessions.Ses
543
543
544 err = requests.New(p.RedeemURL.String()).
544 err = requests.New(p.RedeemURL.String()).
545 WithContext(ctx).
545 WithContext(ctx).
546− WithMethod("POST").
546+ WithMethod(http.MethodPost).
547 WithBody(bytes.NewBufferString(params.Encode())).
547 WithBody(bytes.NewBufferString(params.Encode())).
548 SetHeader("Content-Type", "application/x-www-form-urlencoded").
548 SetHeader("Content-Type", "application/x-www-form-urlencoded").
549 Do().
549 Do().
providers/logingov.go+2−1
@@ -8,6 +8,7 @@ import (
8 "errors"
8 "errors"
9 "fmt"
9 "fmt"
10 "math/big"
10 "math/big"
11+ "net/http"
11 "net/url"
12 "net/url"
12 "os"
13 "os"
13 "time"
14 "time"
@@ -237,7 +238,7 @@ func (p *LoginGovProvider) Redeem(ctx context.Context, _, code, codeVerifier str
237 }
238 }
238 err = requests.New(p.RedeemURL.String()).
239 err = requests.New(p.RedeemURL.String()).
239 WithContext(ctx).
240 WithContext(ctx).
240− WithMethod("POST").
241+ WithMethod(http.MethodPost).
241 WithBody(bytes.NewBufferString(params.Encode())).
242 WithBody(bytes.NewBufferString(params.Encode())).
242 SetHeader("Content-Type", "application/x-www-form-urlencoded").
243 SetHeader("Content-Type", "application/x-www-form-urlencoded").
243 Do().
244 Do().
providers/ms_entra_id.go+2−1
@@ -5,6 +5,7 @@ import (
5 "context"
5 "context"
6 "encoding/json"
6 "encoding/json"
7 "fmt"
7 "fmt"
8+ "net/http"
8 "net/url"
9 "net/url"
9 "os"
10 "os"
10 "regexp"
11 "regexp"
@@ -304,7 +305,7 @@ func (p *MicrosoftEntraIDProvider) checkTenantMatchesTenantList(tenant string, a
304func (p *MicrosoftEntraIDProvider) fetchToken(ctx context.Context, params url.Values) (*oauth2.Token, error) {
305func (p *MicrosoftEntraIDProvider) fetchToken(ctx context.Context, params url.Values) (*oauth2.Token, error) {
305 resp := requests.New(p.RedeemURL.String()).
306 resp := requests.New(p.RedeemURL.String()).
306 WithContext(ctx).
307 WithContext(ctx).
307− WithMethod("POST").
308+ WithMethod(http.MethodPost).
308 WithBody(bytes.NewBufferString(params.Encode())).
309 WithBody(bytes.NewBufferString(params.Encode())).
309 SetHeader("Content-Type", "application/x-www-form-urlencoded").
310 SetHeader("Content-Type", "application/x-www-form-urlencoded").
310 Do()
311 Do()
providers/provider_default.go+2−1
@@ -5,6 +5,7 @@ import (
5 "context"
5 "context"
6 "errors"
6 "errors"
7 "fmt"
7 "fmt"
8+ "net/http"
8 "net/url"
9 "net/url"
9
10
10 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
11 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
@@ -71,7 +72,7 @@ func (p *ProviderData) Redeem(ctx context.Context, redirectURL, code, codeVerifi
71
72
72 result := requests.New(p.RedeemURL.String()).
73 result := requests.New(p.RedeemURL.String()).
73 WithContext(ctx).
74 WithContext(ctx).
74− WithMethod("POST").
75+ WithMethod(http.MethodPost).
75 WithBody(bytes.NewBufferString(params.Encode())).
76 WithBody(bytes.NewBufferString(params.Encode())).
76 SetHeader("Content-Type", "application/x-www-form-urlencoded").
77 SetHeader("Content-Type", "application/x-www-form-urlencoded").
77 Do()
78 Do()
providers/srht.go+2−1
@@ -4,6 +4,7 @@ import (
4 "bytes"
4 "bytes"
5 "context"
5 "context"
6 "fmt"
6 "fmt"
7+ "net/http"
7 "net/url"
8 "net/url"
8
9
9 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
10 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
@@ -75,7 +76,7 @@ func NewSourceHutProvider(p *ProviderData) *SourceHutProvider {
75func (p *SourceHutProvider) EnrichSession(ctx context.Context, s *sessions.SessionState) error {
76func (p *SourceHutProvider) EnrichSession(ctx context.Context, s *sessions.SessionState) error {
76 json, err := requests.New(p.ProfileURL.String()).
77 json, err := requests.New(p.ProfileURL.String()).
77 WithContext(ctx).
78 WithContext(ctx).
78− WithMethod("POST").
79+ WithMethod(http.MethodPost).
79 SetHeader("Content-Type", "application/json").
80 SetHeader("Content-Type", "application/json").
80 SetHeader("Authorization", "Bearer "+s.AccessToken).
81 SetHeader("Authorization", "Bearer "+s.AccessToken).
81 WithBody(bytes.NewBufferString(`{"query": "{ me { username, email } }"}`)).
82 WithBody(bytes.NewBufferString(`{"query": "{ me { username, email } }"}`)).