added new basic auth endpoint

This commit is contained in:
ston1th 2022-08-21 14:59:31 +02:00
commit 8c9ab3b8d2
10 changed files with 249 additions and 51 deletions

View file

@ -576,3 +576,20 @@ func logoutHandler(ctx *Context) {
ctx.SetCookie(nil, 0)
ctx.Redirect(root, http.StatusFound)
}
func authBasicHandler(ctx *Context) {
if ctx.Method() != "GET" {
ctx.PlainUnauthorized()
return
}
username, password, ok := ctx.Request.BasicAuth()
if !ok {
ctx.PlainUnauthorized()
return
}
if ctx.Srv.BasicAuth.Auth(username, password) {
ctx.PlainOK()
return
}
ctx.PlainForbidden()
}