|
@@ -65,6 +65,19 @@ func WsAuthCheck(conn *websocket.Conn) bool {
|
|
|
return false
|
|
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
|
|
// this takes a bool for auth/unauth -- also persists to config
|
|
|
func AddToAuthMap(conn *websocket.Conn, token map[string]string, authed bool) error {
|
|
func AddToAuthMap(conn *websocket.Conn, token map[string]string, authed bool) error {
|
|
|
tokenStr := token["token"]
|
|
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"]))
|
|
// hashed := sha512.Sum512([]byte(token["token"]))
|
|
|
// hash := hex.EncodeToString(hashed[:])
|
|
// hash := hex.EncodeToString(hashed[:])
|
|
|
// you in auth map?
|
|
// you in auth map?
|
|
|
- if WsAuthCheck(conn, token["id"]) {
|
|
|
|
|
|
|
+ if TokenIdAuthed(token["id"]) {
|
|
|
if ip == res["ip"] && userAgent == res["user_agent"] {
|
|
if ip == res["ip"] && userAgent == res["user_agent"] {
|
|
|
config.Logger.Info("Token authenticated")
|
|
config.Logger.Info("Token authenticated")
|
|
|
return true
|
|
return true
|