Ajouter basicauth web

This commit is contained in:
Victor Lacasse-Beaudoin 2023-09-19 16:48:29 -04:00
parent 3b9a51c767
commit a74e36afc1

View file

@ -4,6 +4,7 @@ Copyright © 2023 AGECEM & Victor Lacasse-Beaudoin
package cmd package cmd
import ( import (
"crypto/subtle"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
@ -34,6 +35,12 @@ var webCmd = &cobra.Command{
e.Pre(middleware.AddTrailingSlash()) e.Pre(middleware.AddTrailingSlash())
e.Use(middleware.BasicAuth(func(user, password string, c echo.Context) (bool, error) {
usersMatch := subtle.ConstantTimeCompare([]byte(user), []byte(cfg.Web.User)) == 1
passwordsMatch := subtle.ConstantTimeCompare([]byte(password), []byte(cfg.Web.Password)) == 1
return usersMatch && passwordsMatch, nil
}))
client := http.DefaultClient client := http.DefaultClient
defer client.CloseIdleConnections() defer client.CloseIdleConnections()