reid 2 anos atrás
pai
commit
d841e6ddf5
1 arquivos alterados com 14 adições e 1 exclusões
  1. 14 1
      auth/auth.go

+ 14 - 1
auth/auth.go

@@ -65,6 +65,19 @@ func WsAuthCheck(conn *websocket.Conn) bool {
 	return false
 }
 
+func TokenIdAuthed(token string) bool {
+	AuthenticatedClients.RLock()
+	defer AuthenticatedClients.RUnlock()
+	for tokenID, _ := range AuthenticatedClients.Conns {
+		if token == tokenID {
+			config.Logger.Info(fmt.Sprintf("%s is in auth map",token))
+			return true
+		}
+	}
+	config.Logger.Info("Token not in auth map")
+	return false
+}
+
 // this takes a bool for auth/unauth -- also persists to config
 func AddToAuthMap(conn *websocket.Conn, token map[string]string, authed bool) error {
 	tokenStr := token["token"]
@@ -142,7 +155,7 @@ func CheckToken(token map[string]string, conn *websocket.Conn, r *http.Request,
 		// hashed := sha512.Sum512([]byte(token["token"]))
 		// hash := hex.EncodeToString(hashed[:])
 		// you in auth map?
-		if WsAuthCheck(conn, token["id"]) {
+		if TokenIdAuthed(token["id"]) {
 			if ip == res["ip"] && userAgent == res["user_agent"] {
 				config.Logger.Info("Token authenticated")
 				return true