Skip to content

Commit a97b1dd

Browse files
allow send the token via query param
1 parent 4ff2dd5 commit a97b1dd

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ curl --location --request POST 'rest_gateway:4444/stations/<station_name>/produc
157157
--data-raw '{"message": "New Message"}'
158158
```
159159

160+
#### If you don't have the option to add the authorization header, you can send the JWT via query parameters:
161+
162+
```
163+
curl --location --request POST 'rest_gateway:4444/stations/<station_name>/produce/single?authorization=eyJhbGciOiJIU**********.e30.4KOGRhUaqvm-qSHnmMwX5VrLKsvHo33u3UdJ0qYP0kI' \
164+
--header 'Content-Type: application/json' \
165+
--data-raw '{"message": "New Message"}'
166+
```
167+
160168
Expected output:
161169

162170
```

middlewares/auth.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,13 @@ func Authenticate(c *fiber.Ctx) error {
7171
headers := c.GetReqHeaders()
7272
tokenString, err := extractToken(headers["Authorization"])
7373
if err != nil || tokenString == "" {
74-
log.Warnf("Authentication error - jwt token is missing")
75-
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
76-
"message": "Unauthorized",
77-
})
74+
tokenString = c.Query("authorization")
75+
if tokenString == "" { // fallback - get the token from the query params
76+
log.Warnf("Authentication error - jwt token is missing")
77+
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
78+
"message": "Unauthorized",
79+
})
80+
}
7881
}
7982
err = verifyToken(tokenString, configuration.JWT_SECRET)
8083
if err != nil {

0 commit comments

Comments
 (0)