func Auth(rw http.ResponseWriter, req *http.Request) bool { if !config.Config.Auth { return true } tokenString := req.URL.Query().Get("token") if len(tokenString) == 0 { return false } token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { return config.Config.ParsedPublicKey, nil }) SetToken(req, token) if err != nil { common.CheckError(err, 2) return false } if !token.Valid { return false } if config.Config.HostUuidCheck && token.Claims["hostUuid"] != config.Config.HostUuid { glog.Infoln("Host UUID mismatch , authentication failed") return false } return true }
func GetAndCheckToken(tokenString string) (*jwt.Token, bool) { token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { return config.Config.ParsedPublicKey, nil }) if err != nil { common.CheckError(err, 2) return token, false } if !token.Valid { return token, false } if config.Config.HostUuidCheck && token.Claims["hostUuid"] != config.Config.HostUuid { glog.Infoln("Host UUID mismatch , authentication failed") return token, false } return token, true }