diff --git a/Sora/Net/SoraWebsocketClient.cs b/Sora/Net/SoraWebsocketClient.cs index 47be17c..cf12463 100644 --- a/Sora/Net/SoraWebsocketClient.cs +++ b/Sora/Net/SoraWebsocketClient.cs @@ -234,7 +234,8 @@ public void Dispose() private ClientWebSocket CreateSocket() { ClientWebSocket clientWebSocket = new(); - clientWebSocket.Options.SetRequestHeader("Authorization", $"Bearer {Config.AccessToken}"); + if (!string.IsNullOrEmpty(Config.AccessToken)) + clientWebSocket.Options.SetRequestHeader("Authorization", $"Bearer {Config.AccessToken}"); return clientWebSocket; } diff --git a/Sora/Net/SoraWebsocketServer.cs b/Sora/Net/SoraWebsocketServer.cs index d633944..d9d36da 100644 --- a/Sora/Net/SoraWebsocketServer.cs +++ b/Sora/Net/SoraWebsocketServer.cs @@ -259,8 +259,10 @@ private bool CheckRequest(IWebSocketConnection socket, out string selfId) } //获取Token - if (socket.ConnectionInfo.Headers.TryGetValue("Authorization", out string headerValue)) + if (socket.ConnectionInfo.Headers.TryGetValue("Authorization", out string headerValue) && !string.IsNullOrEmpty(Config.AccessToken)) { + if(headerValue.Length <= 7) + return false; string token = headerValue.Split(' ')[1]; Log.Debug("Server", $"get token = {token}"); //验证Token