Auth: Fix POST request failures with anonymous access (#26049)

Macaron context.QueryBool() seems to modify the request context
that causes the POST and PUT requests to fail with:
"http: proxy error: net/http: HTTP/1.x transport connection broken: http: ContentLength=333 with Body length 0"

(cherry picked from commit 44dff6fdd0)
This commit is contained in:
Sofia Papagiannaki
2020-07-13 14:41:21 +02:00
committed by Andrej Ocenas
parent fc96444b23
commit 28e50ae4fd
+8 -1
View File
@@ -2,6 +2,7 @@ package middleware
import (
"net/url"
"strconv"
"strings"
macaron "gopkg.in/macaron.v1"
@@ -87,7 +88,13 @@ func RoleAuth(roles ...models.RoleType) macaron.Handler {
func Auth(options *AuthOptions) macaron.Handler {
return func(c *models.ReqContext) {
forceLogin := c.AllowAnonymous && c.QueryBool("forceLogin")
forceLogin := false
if c.AllowAnonymous {
forceLoginParam, err := strconv.ParseBool(c.Req.URL.Query().Get("forceLogin"))
if err == nil {
forceLogin = forceLoginParam
}
}
requireLogin := !c.AllowAnonymous || forceLogin
if !c.IsSignedIn && options.ReqSignedIn && requireLogin {
notAuthorized(c)