Skip to content

Commit 0a8c2b4

Browse files
auth middleware bugfix
1 parent a96d212 commit 0a8c2b4

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

middlewares/auth.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,23 @@ func Authenticate(c *fiber.Ctx) error {
9797
path = strings.Split(path, "?")[0]
9898
if isAuthNeeded(path) {
9999
headers := c.GetReqHeaders()
100+
tokenString := ""
100101
if len(headers["Authorization"]) == 0 {
101-
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
102-
"message": "Unauthorized",
103-
})
104-
}
105-
tokenString, err := extractToken(headers["Authorization"][0])
106-
if err != nil || tokenString == "" {
107102
tokenString = c.Query("authorization")
108-
if tokenString == "" { // fallback - get the token from the query params
109-
log.Warnf("Authentication error - jwt token is missing")
110-
if configuration.DEBUG {
111-
fmt.Printf("Method: %s, Path: %s, IP: %s\nBody: %s\n", c.Method(), c.Path(), c.IP(), string(c.Body()))
112-
}
103+
if tokenString == "" {
104+
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
105+
"message": "Unauthorized",
106+
})
107+
}
108+
} else {
109+
tokenString, err = extractToken(headers["Authorization"][0])
110+
if err != nil || tokenString == "" {
113111
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
114112
"message": "Unauthorized",
115113
})
116114
}
117115
}
116+
118117
user, err = verifyToken(tokenString, configuration.JWT_SECRET)
119118
if err != nil {
120119
log.Warnf("Authentication error - jwt token validation has failed")

0 commit comments

Comments
 (0)