From d4e3af67261df3f76af0b7437997c01444c9a2da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=84=86=E9=A5=BC=E5=B9=B2?= Date: Tue, 16 Jan 2024 17:37:33 +0800 Subject: [PATCH] fix: AccessToken null --- Sora/Net/SoraWebsocketClient.cs | 3 ++- Sora/Net/SoraWebsocketServer.cs | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) 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