Implement admin media approval endpoints and add JWT role-based auth - NOT TESTED
This commit is contained in:
@@ -43,7 +43,7 @@ func (j *JwtTokenGenerator) GinMiddleware() gin.HandlerFunc {
|
||||
c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"})
|
||||
return
|
||||
}
|
||||
_, err = jwt.Parse(token.Value, func(t *jwt.Token) (interface{}, error) {
|
||||
t, err := jwt.Parse(token.Value, func(t *jwt.Token) (interface{}, error) {
|
||||
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||
return nil, jwt.ErrSignatureInvalid
|
||||
}
|
||||
@@ -53,6 +53,11 @@ func (j *JwtTokenGenerator) GinMiddleware() gin.HandlerFunc {
|
||||
c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"})
|
||||
return
|
||||
}
|
||||
claims, ok := t.Claims.(jwt.MapClaims)
|
||||
if !ok || claims["role"] != "admin" { // Check role, only if its admin let it go
|
||||
c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"})
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user