44using System . Text ;
55using Npgsql ;
66using NpgsqlTypes ;
7- using static NpgsqlRest . NpgsqlRestOptions ;
87
98namespace NpgsqlRest . Auth ;
109
@@ -13,9 +12,7 @@ public static class BasicAuthHandler
1312 public static async Task HandleAsync (
1413 HttpContext context ,
1514 RoutineEndpoint endpoint ,
16-
17- NpgsqlConnection connection ,
18- ILogger ? logger )
15+ NpgsqlConnection connection )
1916 {
2017 var realm =
2118 string . IsNullOrEmpty ( endpoint . BasicAuth ? . Realm ) ?
@@ -26,23 +23,23 @@ public static async Task HandleAsync(
2623 {
2724 if ( Options . AuthenticationOptions . BasicAuth . SslRequirement == SslRequirement . Required )
2825 {
29- logger ? . LogError ( "Basic authentication with SslRequirement 'Required' cannot be used when SSL is disabled." ) ;
26+ Logger ? . LogError ( "Basic authentication with SslRequirement 'Required' cannot be used when SSL is disabled." ) ;
3027 await Challenge ( context , realm ) ;
3128 return ;
3229 }
3330 if ( Options . AuthenticationOptions . BasicAuth . SslRequirement == SslRequirement . Warning )
3431 {
35- logger ? . LogWarning ( "Using Basic Authentication when SSL is disabled." ) ;
32+ Logger ? . LogWarning ( "Using Basic Authentication when SSL is disabled." ) ;
3633 }
3734 else if ( Options . AuthenticationOptions . BasicAuth . SslRequirement == SslRequirement . Ignore )
3835 {
39- logger ? . LogDebug ( "WARNING: Using Basic Authentication when SSL is disabled." ) ;
36+ Logger ? . LogDebug ( "WARNING: Using Basic Authentication when SSL is disabled." ) ;
4037 }
4138 }
4239
4340 if ( context . Request . Headers . TryGetValue ( "Authorization" , out var authHeader ) is false )
4441 {
45- logger ? . LogWarning ( "No Authorization header found in request with Basic Authentication Realm {realm}. Request: {Path}" ,
42+ Logger ? . LogWarning ( "No Authorization header found in request with Basic Authentication Realm {realm}. Request: {Path}" ,
4643 realm ,
4744 string . Concat ( endpoint . Method . ToString ( ) , endpoint . Path ) ) ;
4845 await Challenge ( context , realm ) ;
@@ -52,7 +49,7 @@ public static async Task HandleAsync(
5249 var authValue = authHeader . FirstOrDefault ( ) ;
5350 if ( string . IsNullOrEmpty ( authValue ) || ! authValue . StartsWith ( "Basic " ) )
5451 {
55- logger ? . LogWarning ( "Authorization header value missing or malformed found in request with Basic Authentication Realm {realm}. Request: {Path}" ,
52+ Logger ? . LogWarning ( "Authorization header value missing or malformed found in request with Basic Authentication Realm {realm}. Request: {Path}" ,
5653 realm ,
5754 string . Concat ( endpoint . Method . ToString ( ) , endpoint . Path ) ) ;
5855 await Challenge ( context , realm ) ;
@@ -67,7 +64,7 @@ public static async Task HandleAsync(
6764 }
6865 catch ( Exception ex )
6966 {
70- logger ? . LogError ( ex , "Failed to decode Basic Authentication credentials in request with Basic Authentication Realm {realm}. Request: {Path}" ,
67+ Logger ? . LogError ( ex , "Failed to decode Basic Authentication credentials in request with Basic Authentication Realm {realm}. Request: {Path}" ,
7168 realm ,
7269 string . Concat ( endpoint . Method . ToString ( ) , endpoint . Path ) ) ;
7370 await Challenge ( context , realm ) ;
@@ -77,7 +74,7 @@ public static async Task HandleAsync(
7774 var colonIndex = decodedCredentials . IndexOf ( ':' ) ;
7875 if ( colonIndex == - 1 )
7976 {
80- logger ? . LogWarning ( "Authorization header value malformed found in request with Basic Authentication Realm {realm}. Request: {Path}" ,
77+ Logger ? . LogWarning ( "Authorization header value malformed found in request with Basic Authentication Realm {realm}. Request: {Path}" ,
8178 realm ,
8279 string . Concat ( endpoint . Method . ToString ( ) , endpoint . Path ) ) ;
8380 await Challenge ( context , realm ) ;
@@ -88,7 +85,7 @@ public static async Task HandleAsync(
8885
8986 if ( string . IsNullOrEmpty ( username ) is true || string . IsNullOrEmpty ( password ) is true )
9087 {
91- logger ? . LogWarning ( "Username or password missing in request with Basic Authentication Realm {realm}. Request: {Path}" ,
88+ Logger ? . LogWarning ( "Username or password missing in request with Basic Authentication Realm {realm}. Request: {Path}" ,
9289 realm ,
9390 string . Concat ( endpoint . Method . ToString ( ) , endpoint . Path ) ) ;
9491 await Challenge ( context , realm ) ;
@@ -114,7 +111,7 @@ public static async Task HandleAsync(
114111 {
115112 if ( Options . AuthenticationOptions . PasswordHasher is null )
116113 {
117- logger ? . LogError ( "PasswordHasher not configured for Basic Authentication Realm {realm}. Request: {Path}" ,
114+ Logger ? . LogError ( "PasswordHasher not configured for Basic Authentication Realm {realm}. Request: {Path}" ,
118115 realm ,
119116 string . Concat ( endpoint . Method . ToString ( ) , endpoint . Path ) ) ;
120117 await Challenge ( context , realm ) ;
@@ -133,7 +130,7 @@ public static async Task HandleAsync(
133130 if ( string . IsNullOrEmpty ( challengeCommand ) is true )
134131 {
135132 // misconfigured: no user with password configured and no challenge command
136- logger ? . LogError ( "No Basic Authentication user configured for user {username} in request with Basic Authentication Realm {realm}. Request: {Path}" ,
133+ Logger ? . LogError ( "No Basic Authentication user configured for user {username} in request with Basic Authentication Realm {realm}. Request: {Path}" ,
137134 username ,
138135 realm ,
139136 string . Concat ( endpoint . Method . ToString ( ) , endpoint . Path ) ) ;
@@ -176,7 +173,6 @@ await LoginHandler.HandleAsync(
176173 command ,
177174 context ,
178175 endpoint . RetryStrategy ,
179- logger ,
180176 tracePath : string . Concat ( endpoint . Method . ToString ( ) , " " , endpoint . Path ) ,
181177 performHashVerification : false ,
182178 assignUserPrincipalToContext : true ) ;
@@ -186,7 +182,7 @@ await LoginHandler.HandleAsync(
186182 return ;
187183 }
188184
189- logger ? . LogError ( "ChallengeCommand denied user {username} in request with Basic Authentication Realm {realm}. Request: {Path}" ,
185+ Logger ? . LogError ( "ChallengeCommand denied user {username} in request with Basic Authentication Realm {realm}. Request: {Path}" ,
190186 username ,
191187 realm ,
192188 string . Concat ( endpoint . Method . ToString ( ) , endpoint . Path ) ) ;
@@ -207,7 +203,7 @@ await LoginHandler.HandleAsync(
207203 }
208204 else
209205 {
210- logger ? . LogWarning ( "Invalid password for user {username} in request with Basic Authentication Realm {realm}. Request: {Path}" ,
206+ Logger ? . LogWarning ( "Invalid password for user {username} in request with Basic Authentication Realm {realm}. Request: {Path}" ,
211207 username ,
212208 realm ,
213209 string . Concat ( endpoint . Method . ToString ( ) , endpoint . Path ) ) ;
0 commit comments