Skip to content

Commit

Permalink
fix: AccessToken null
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukari316 committed Jan 16, 2024
1 parent 60daf80 commit d4e3af6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Sora/Net/SoraWebsocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion Sora/Net/SoraWebsocketServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4e3af6

Please sign in to comment.