Skip to content

Commit 56ee98b

Browse files
committed
[Milky] Fix access token validation logic
1 parent 71cbc22 commit 56ee98b

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

Lagrange.Milky/Api/MilkyHttpApiService.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,12 @@ private async Task<bool> ValidateHttpContextAsync(HttpListenerContext context, C
126126

127127
private bool ValidateAccessToken(HttpListenerContext context)
128128
{
129-
if (_token == null) return true;
129+
if (string.IsNullOrEmpty(_token)) return true;
130130

131131
string? authorization = context.Request.Headers["Authorization"];
132132
if (authorization == null) return false;
133-
if (!authorization.StartsWith("Bearer")) return false;
134-
135-
if (_token == string.Empty && authorization.Length == 6) return true;
136-
137-
return authorization[7..] == _token;
133+
if (!authorization.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase)) return false;
134+
return authorization.AsSpan(7..).Equals(_token);
138135
}
139136

140137
private async Task<IApiHandler?> GetApiHandlerAsync(HttpListenerContext context, CancellationToken token)

0 commit comments

Comments
 (0)