Browse Source

feat: add multiple basic auth account

pull/34/head
Aldino Kemal 3 years ago
parent
commit
827d53a0ec
  1. 13
      src/cmd/root.go

13
src/cmd/root.go

@ -74,17 +74,22 @@ func runRest(_ *cobra.Command, _ []string) {
}))
if config.AppBasicAuthCredential != "" {
ba := strings.Split(config.AppBasicAuthCredential, ":")
account := make(map[string]string, 0)
multipleBA := strings.Split(config.AppBasicAuthCredential, ",")
for _, basicAuth := range multipleBA {
ba := strings.Split(basicAuth, ":")
if len(ba) != 2 {
log.Fatalln("Basic auth is not valid, please this following format <user>:<secret>")
}
account[ba[0]] = ba[1]
}
if account != nil {
app.Use(basicauth.New(basicauth.Config{
Users: map[string]string{
ba[0]: ba[1],
},
Users: account,
}))
}
}
db := utils.InitWaDB()
cli := utils.InitWaCLI(db)

Loading…
Cancel
Save