Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions BasicAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,8 @@ public async Task Invoke(HttpContext context)
return;
}

if (!TryGetCredentials(context, out string username, out string password, out bool hadAuthorizationHeader))
if (!TryGetCredentials(context, out string username, out string password))
{
if (hadAuthorizationHeader)
{
RegisterFailedAttempt(clientKey, null, now);
}

WriteUnauthorizedResponse(context);
return;
}
Expand Down Expand Up @@ -154,18 +149,16 @@ public bool IsAuthorized(string username, string password)
return SecureEquals(expectedPassword, password);
}

private bool TryGetCredentials(HttpContext context, out string username, out string password, out bool hadAuthorizationHeader)
private bool TryGetCredentials(HttpContext context, out string username, out string password)
{
username = string.Empty;
password = string.Empty;
hadAuthorizationHeader = false;

if (!context.Request.Headers.TryGetValue(HttpAuthorizationHeader, out var authorizationValues))
{
return false;
}

hadAuthorizationHeader = true;
string authorizationHeader = authorizationValues.ToString();
if (string.IsNullOrWhiteSpace(authorizationHeader))
{
Expand Down