Undid last commit and added auth challenge

This commit is contained in:
Asaf Gartner 2021-09-24 03:37:08 +03:00
parent ed85d11d96
commit aa2e12496a
1 changed files with 7 additions and 4 deletions

View File

@ -40,10 +40,13 @@ func AdminAtomFeed(c *RequestContext) ResponseData {
creds := fmt.Sprintf("%s:%s", config.Config.Admin.AtomUsername, config.Config.Admin.AtomPassword)
expectedAuth := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(creds)))
auth, hasAuth := c.Req.Header["Authorization"]
if hasAuth {
c.Logger.Warn().Str("auth", auth[0]).Msg("Got auth")
if !hasAuth {
res := ResponseData{
StatusCode: http.StatusUnauthorized,
}
if !hasAuth || auth[0] != expectedAuth {
res.Header().Set("WWW-Authenticate", "Basic realm=\"Admin\"")
return res
} else if auth[0] != expectedAuth {
return FourOhFour(c)
}