Browse Source

feat: add basic auth in params (#22)

* feat: add basic auth in params

* chore: update version

Co-authored-by: Aldino Kemal <aldino.kemal-mitrais@xendit.co>
pull/23/head
Aldino Kemal 3 years ago
committed by GitHub
parent
commit
9731109245
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/cmd/root.go
  2. 3
      src/config/settings.go

16
src/cmd/root.go

@ -9,6 +9,7 @@ import (
"github.com/aldinokemal/go-whatsapp-web-multidevice/utils"
"github.com/dustin/go-humanize"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/basicauth"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/template/html"
@ -16,6 +17,7 @@ import (
_ "github.com/mattn/go-sqlite3"
"log"
"os"
"strings"
"github.com/spf13/cobra"
)
@ -32,6 +34,7 @@ func init() {
rootCmd.CompletionOptions.DisableDefaultCmd = true
rootCmd.PersistentFlags().StringVarP(&config.AppPort, "port", "p", config.AppPort, "change port number with --port <number> | example: --port=8080")
rootCmd.PersistentFlags().BoolVarP(&config.AppDebug, "debug", "d", config.AppDebug, "hide or displaying log with --debug <true/false> | example: --debug=true")
rootCmd.PersistentFlags().StringVarP(&config.AppBasicAuthCredential, "basic-auth", "b", config.AppBasicAuthCredential, "basic auth credential | yourUsername:yourPassword")
rootCmd.PersistentFlags().StringVarP(&config.WhatsappAutoReplyMessage, "autoreply", "", config.WhatsappAutoReplyMessage, `auto reply when received message --autoreply <string> | example: --autoreply="Don't reply this message"`)
}
@ -75,6 +78,19 @@ func runRest(cmd *cobra.Command, args []string) {
sendController := controllers.NewSendController(sendService)
userController := controllers.NewUserController(userService)
if config.AppBasicAuthCredential != "" {
ba := strings.Split(config.AppBasicAuthCredential, ":")
if len(ba) != 2 {
log.Fatalln("Basic auth is not valid, please this following format <user>:<secret>")
}
app.Use(basicauth.New(basicauth.Config{
Users: map[string]string{
ba[0]: ba[1],
},
}))
}
appController.Route(app)
sendController.Route(app)
userController.Route(app)

3
src/config/settings.go

@ -8,10 +8,11 @@ import (
type Browser string
var (
AppVersion string = "v3.4.1"
AppVersion string = "v3.5.0"
AppPort string = "3000"
AppDebug bool = false
AppOs string = fmt.Sprintf("AldinoKemal")
AppBasicAuthCredential string
AppPlatform waProto.DeviceProps_PlatformType = waProto.DeviceProps_PlatformType(1)
PathQrCode string = "statics/qrcode"

Loading…
Cancel
Save