Skip to content

Commit

Permalink
run basic auth only for reports (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
acn-sbuad authored Mar 13, 2024
1 parent 26734f0 commit 89f37d7
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.Text;
using System.Text.Encodings.Web;

using Azure.Core;

using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
Expand Down Expand Up @@ -42,18 +40,18 @@ public BasicAuthenticationHandler(
/// </summary>
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
{
if (!Request.Path.StartsWithSegments("/notifications/sms/api/v1/reports"))
{
// Bypass authentication for all endspoint not reports related
return Task.FromResult(AuthenticateResult.NoResult());
}

string username = string.Empty;
string password = string.Empty;

if (!Request.Headers.TryGetValue("Authorization", out var authorizationHeader))
{
#pragma warning disable SA1305
StringValues ipAddres;

Request.Headers.TryGetValue("X-Forwarded-For", out ipAddres);

_logger.LogError("// BasicAuthenticationHandler // HandleAuthenticateAsync // Missing Authorization Header. IP: {0}", System.Text.Json.JsonSerializer.Serialize(ipAddres));
#pragma warning restore SA1305
_logger.LogError("// BasicAuthenticationHandler // HandleAuthenticateAsync // Missing Authorization Header.");

return Task.FromResult(AuthenticateResult.Fail("Missing Authorization Header"));
}
Expand Down

0 comments on commit 89f37d7

Please sign in to comment.