Merge pull request #107 from gravitl/hotfix_v0.2_jwt

fixed JWT token auth
This commit is contained in:
Alex 2021-04-19 21:52:29 -04:00 committed by GitHub
commit ae945e786d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 5 deletions

View file

@ -1,5 +1,5 @@
server:
host: "localhost"
host: "3.231.219.63"
apiport: "8081"
grpcport: "50051"
masterkey: "secretkey"

View file

@ -9,7 +9,7 @@ import (
"net/http"
"strings"
"time"
"os"
"github.com/gorilla/mux"
"github.com/gravitl/netmaker/config"
"github.com/gravitl/netmaker/functions"
@ -83,7 +83,7 @@ func securityCheck(next http.Handler) http.HandlerFunc {
//Consider a more secure way of setting master key
func authenticateMaster(tokenString string) bool {
if tokenString == config.Config.Server.MasterKey {
if tokenString == config.Config.Server.MasterKey || (tokenString == os.Getenv("MASTER_KEY") && tokenString != "") {
return true
}
return false

View file

@ -2,6 +2,7 @@ package functions
import (
"time"
"os"
"github.com/gravitl/netmaker/config"
"github.com/gravitl/netmaker/models"
"github.com/dgrijalva/jwt-go"
@ -50,7 +51,7 @@ func CreateUserJWT(username string, isadmin bool) (response string, err error) {
func VerifyUserToken(tokenString string) (username string, isadmin bool, err error) {
claims := &models.UserClaims{}
if tokenString == config.Config.Server.MasterKey || os.Getenv("MASTER_KEY") {
if tokenString == config.Config.Server.MasterKey || (tokenString == os.Getenv("MASTER_KEY") && tokenString != "") {
return "masteradministrator", true, nil
}
@ -70,7 +71,7 @@ func VerifyToken(tokenString string) (macaddress string, network string, err err
//this may be a stupid way of serving up a master key
//TODO: look into a different method. Encryption?
if tokenString == config.Config.Server.MasterKey || os.Getenv("MASTER_KEY") {
if tokenString == config.Config.Server.MasterKey || (tokenString == os.Getenv("MASTER_KEY") && tokenString != "") {
return "mastermac", "", nil
}

View file

@ -38,6 +38,7 @@ var PortGRPC string
//Start MongoDB Connection and start API Request Handler
func main() {
var clientmode string
var defaultnet string
flag.StringVar(&clientmode, "clientmode", "on", "Have a client on the server")