Ajouter basicauth web
This commit is contained in:
parent
3b9a51c767
commit
a74e36afc1
1 changed files with 7 additions and 0 deletions
|
@ -4,6 +4,7 @@ Copyright © 2023 AGECEM & Victor Lacasse-Beaudoin
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -34,6 +35,12 @@ var webCmd = &cobra.Command{
|
|||
|
||||
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
|
||||
defer client.CloseIdleConnections()
|
||||
|
||||
|
|
Reference in a new issue