Skip to content

Commit

Permalink
fix: Update Auth middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
sirateek committed Apr 23, 2023
1 parent abe122e commit 9c47a67
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions httpserver/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

func AuthModelMapping() gin.HandlerFunc {
Expand All @@ -18,15 +19,21 @@ func AuthModelMapping() gin.HandlerFunc {

key := c.GetHeader("Authorization")

if key == "" {
key = c.GetHeader("authorization")
}

splittedKey := strings.Split(key, " ")
if len(splittedKey) != 2 {
logrus.Warn("Key not correctly structed.")
c.AbortWithStatus(http.StatusForbidden)
return
}
tokenStr := splittedKey[1]

token, err := jwt.Parse(tokenStr, nil)
if token == nil || err != nil {
logrus.Warn("Can't parse jwt")
c.AbortWithStatus(http.StatusForbidden)
return
}
Expand Down

0 comments on commit 9c47a67

Please sign in to comment.