diff options
author | Unknwon <u@gogs.io> | 2018-09-14 22:29:43 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2018-09-14 22:29:43 -0400 |
commit | 520530dfcf34fdf1a521d561dd95cf6fcbc76d64 (patch) | |
tree | 96afbbd0b4b96ea041c3ad6463d2503bfb6763ca /pkg/context | |
parent | 31c18b4bc729241ebc711abc24aac5860e2359a7 (diff) |
metrics: add initial Prometheus support (#4141)
Diffstat (limited to 'pkg/context')
-rw-r--r-- | pkg/context/auth.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/pkg/context/auth.go b/pkg/context/auth.go index 60c020a0..facc9631 100644 --- a/pkg/context/auth.go +++ b/pkg/context/auth.go @@ -5,13 +5,16 @@ package context import ( + "net/http" "net/url" + "strings" "github.com/go-macaron/csrf" "gopkg.in/macaron.v1" "github.com/gogs/gogs/pkg/auth" "github.com/gogs/gogs/pkg/setting" + "github.com/gogs/gogs/pkg/tool" ) type ToggleOptions struct { @@ -92,3 +95,18 @@ func Toggle(options *ToggleOptions) macaron.Handler { } } } + +// RequireBasicAuth verifies HTTP Basic Authentication header with given credentials +func (c *Context) RequireBasicAuth(username, password string) { + fields := strings.Fields(c.Req.Header.Get("Authorization")) + if len(fields) != 2 || fields[0] != "Basic" { + c.Status(http.StatusUnauthorized) + return + } + + uname, passwd, _ := tool.BasicAuthDecode(fields[1]) + if uname != username || passwd != password { + c.Status(http.StatusForbidden) + return + } +} |