File tree Expand file tree Collapse file tree 2 files changed +13
-27
lines changed
trino-csharp/Trino.Client/Auth Expand file tree Collapse file tree 2 files changed +13
-27
lines changed Original file line number Diff line number Diff line change 55namespace Trino . Client . Auth
66{
77 /// <summary>
8- /// For testing purposes, you can use the BasicAuth class to authenticate with Trino .
8+ /// For setting up basic authentication with a username and optional password .
99 /// </summary>
1010 public class BasicAuth : ITrinoAuth
1111 {
@@ -19,7 +19,12 @@ public string User
1919 set ;
2020 }
2121
22- public void AuthorizeAndValidate ( )
22+ public string Password {
23+ get ;
24+ set ;
25+ }
26+
27+ public virtual void AuthorizeAndValidate ( )
2328 {
2429 if ( string . IsNullOrEmpty ( User ) )
2530 {
@@ -33,7 +38,10 @@ public void AuthorizeAndValidate()
3338 /// <param name="httpRequestMessage">Http request message</param>
3439 public virtual void AddCredentialToRequest ( HttpRequestMessage httpRequestMessage )
3540 {
36- var credentials = Convert . ToBase64String ( Encoding . ASCII . GetBytes ( $ "{ User } " ) ) ;
41+ var credentials = Convert . ToBase64String ( string . IsNullOrEmpty ( Password ) ?
42+ Encoding . ASCII . GetBytes ( $ "{ User } ") :
43+ Encoding . ASCII . GetBytes ( $ "{ User } :{ Password } ") ) ;
44+
3745 httpRequestMessage . Headers . Add ( "Authorization" , "Basic " + credentials ) ;
3846 }
3947 }
Original file line number Diff line number Diff line change 44
55namespace Trino . Client . Auth
66{
7- public class LDAPAuth : ITrinoAuth
7+ public class LDAPAuth : BasicAuth
88 {
99 public LDAPAuth ( )
1010 {
1111 }
1212
13- public string User
14- {
15- get ;
16- set ;
17- }
18-
19- public string Password
20- {
21- get ;
22- set ;
23- }
24-
25- public void AuthorizeAndValidate ( )
13+ public override void AuthorizeAndValidate ( )
2614 {
2715 if ( string . IsNullOrEmpty ( User ) || string . IsNullOrEmpty ( Password ) )
2816 {
2917 throw new ArgumentException ( "LDAPAuth: username or password property is null or empty" ) ;
3018 }
3119 }
32-
33- /// <summary>
34- /// Modify the request with authentication
35- /// </summary>
36- /// <param name="httpRequestMessage">Http request message</param>
37- public virtual void AddCredentialToRequest ( HttpRequestMessage httpRequestMessage )
38- {
39- var credentials = Convert . ToBase64String ( Encoding . ASCII . GetBytes ( $ "{ User } :{ Password } ") ) ;
40- httpRequestMessage . Headers . Add ( "Authorization" , "Basic " + credentials ) ;
41- }
4220 }
4321}
You can’t perform that action at this time.
0 commit comments