Browse Source

fix: change auth token name

pull/125/head
Aldino Kemal 2 years ago
parent
commit
c09d74ebe4
  1. 2
      src/cmd/root.go
  2. 4
      src/internal/rest/middleware/basicauth.go

2
src/cmd/root.go

@ -121,7 +121,7 @@ func runRest(_ *cobra.Command, _ []string) {
return c.Render("views/index", fiber.Map{ return c.Render("views/index", fiber.Map{
"AppHost": fmt.Sprintf("%s://%s", c.Protocol(), c.Hostname()), "AppHost": fmt.Sprintf("%s://%s", c.Protocol(), c.Hostname()),
"AppVersion": config.AppVersion, "AppVersion": config.AppVersion,
"BasicAuthToken": c.UserContext().Value(middleware.AuthToken("token")),
"BasicAuthToken": c.UserContext().Value(middleware.AuthorizationValue("BASIC_AUTH")),
"MaxFileSize": humanize.Bytes(uint64(config.WhatsappSettingMaxFileSize)), "MaxFileSize": humanize.Bytes(uint64(config.WhatsappSettingMaxFileSize)),
"MaxVideoSize": humanize.Bytes(uint64(config.WhatsappSettingMaxVideoSize)), "MaxVideoSize": humanize.Bytes(uint64(config.WhatsappSettingMaxVideoSize)),
}) })

4
src/internal/rest/middleware/basicauth.go

@ -5,13 +5,13 @@ import (
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
type AuthToken string
type AuthorizationValue string
func BasicAuth() fiber.Handler { func BasicAuth() fiber.Handler {
return func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error {
token := string(c.Request().Header.Peek("Authorization")) token := string(c.Request().Header.Peek("Authorization"))
if token != "" { if token != "" {
ctx := context.WithValue(c.Context(), AuthToken("token"), token)
ctx := context.WithValue(c.Context(), AuthorizationValue("BASIC_AUTH"), token)
c.SetUserContext(ctx) c.SetUserContext(ctx)
} }

Loading…
Cancel
Save