diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-12-13 16:59:51 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-13 16:59:51 -0600 |
| commit | 1d27718843b0d62afa8a52847eadcbdbcbf44b98 (patch) | |
| tree | bc6d2bd7fd959d0740a68b5b35a3baf8f1de31c0 /src/slskd/Common/Authentication/ApiKeyAuthentication.cs | |
| parent | 6dbedb038a152a22dd9ee4b04a41a8b3ffde5d1f (diff) | |
| parent | 54584b8edd08f704427355d59323163086102207 (diff) | |
| download | slskd-1d27718843b0d62afa8a52847eadcbdbcbf44b98.tar.gz | |
Merge branch 'master' into copilot/add-sort-directories-files
Diffstat (limited to 'src/slskd/Common/Authentication/ApiKeyAuthentication.cs')
| -rw-r--r-- | src/slskd/Common/Authentication/ApiKeyAuthentication.cs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/slskd/Common/Authentication/ApiKeyAuthentication.cs b/src/slskd/Common/Authentication/ApiKeyAuthentication.cs index 1aaa4a4f..e2733442 100644 --- a/src/slskd/Common/Authentication/ApiKeyAuthentication.cs +++ b/src/slskd/Common/Authentication/ApiKeyAuthentication.cs @@ -15,6 +15,7 @@ // along with this program. If not, see https://www.gnu.org/licenses/. // </copyright> +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace slskd.Authentication @@ -24,7 +25,7 @@ namespace slskd.Authentication using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; - using Microsoft.Extensions.Logging; + using Serilog; /// <summary> /// API key authentication. @@ -51,7 +52,7 @@ namespace slskd.Authentication /// <param name="urlEncoder">A url encoder.</param> public ApiKeyAuthenticationHandler( IOptionsMonitor<ApiKeyAuthenticationOptions> apiKeyOptionsMonitor, - ISecurityService securityService, + SecurityService securityService, ILoggerFactory logger, UrlEncoder urlEncoder) : base(apiKeyOptionsMonitor, logger, urlEncoder) @@ -59,7 +60,8 @@ namespace slskd.Authentication Security = securityService; } - private ISecurityService Security { get; } + private ILogger Log { get; } = Serilog.Log.ForContext<ApiKeyAuthenticationHandler>(); + private SecurityService Security { get; } /// <summary> /// Authenticates via API key. @@ -86,6 +88,7 @@ namespace slskd.Authentication } catch (Exception ex) { + Log.Warning("Unauthorized request from IP address {IP}: {Message}", Request.HttpContext.Connection.RemoteIpAddress, ex.Message); return AuthenticateResult.Fail(ex); } } |
