admin user auth working

This commit is contained in:
afeiszli
2021-05-29 20:18:22 +00:00
parent 02ec2df48a
commit 4f531e1c54
7 changed files with 33 additions and 59 deletions

View File

@@ -2,6 +2,7 @@ package controller
import (
"github.com/gravitl/netmaker/models"
"github.com/gravitl/netmaker/functions"
"github.com/gravitl/netmaker/serverctl"
"github.com/gravitl/netmaker/servercfg"
"encoding/json"
@@ -38,13 +39,16 @@ func securityCheckServer(next http.Handler) http.HandlerFunc {
}
//all endpoints here require master so not as complicated
//still might not be a good way of doing this
if !hasBearer || !authenticateMasterServer(authToken) {
errorResponse = models.ErrorResponse{
Code: http.StatusUnauthorized, Message: "W1R3: You are unauthorized to access this endpoint.",
_, isadmin, err := functions.VerifyUserToken(authToken)
if err != nil || !isadmin {
if (!hasBearer || !authenticateMasterServer(authToken)) && !isadmin {
errorResponse = models.ErrorResponse{
Code: http.StatusUnauthorized, Message: "W1R3: You are unauthorized to access this endpoint.",
}
returnErrorResponse(w, r, errorResponse)
} else {
next.ServeHTTP(w, r)
}
returnErrorResponse(w, r, errorResponse)
} else {
next.ServeHTTP(w, r)
}
}
}