File tree 2 files changed +13
-27
lines changed
trino-csharp/Trino.Client/Auth
2 files changed +13
-27
lines changed Original file line number Diff line number Diff line change 5
5
namespace Trino . Client . Auth
6
6
{
7
7
/// <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 .
9
9
/// </summary>
10
10
public class BasicAuth : ITrinoAuth
11
11
{
@@ -19,7 +19,12 @@ public string User
19
19
set ;
20
20
}
21
21
22
- public void AuthorizeAndValidate ( )
22
+ public string Password {
23
+ get ;
24
+ set ;
25
+ }
26
+
27
+ public virtual void AuthorizeAndValidate ( )
23
28
{
24
29
if ( string . IsNullOrEmpty ( User ) )
25
30
{
@@ -33,7 +38,10 @@ public void AuthorizeAndValidate()
33
38
/// <param name="httpRequestMessage">Http request message</param>
34
39
public virtual void AddCredentialToRequest ( HttpRequestMessage httpRequestMessage )
35
40
{
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
+
37
45
httpRequestMessage . Headers . Add ( "Authorization" , "Basic " + credentials ) ;
38
46
}
39
47
}
Original file line number Diff line number Diff line change 4
4
5
5
namespace Trino . Client . Auth
6
6
{
7
- public class LDAPAuth : ITrinoAuth
7
+ public class LDAPAuth : BasicAuth
8
8
{
9
9
public LDAPAuth ( )
10
10
{
11
11
}
12
12
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 ( )
26
14
{
27
15
if ( string . IsNullOrEmpty ( User ) || string . IsNullOrEmpty ( Password ) )
28
16
{
29
17
throw new ArgumentException ( "LDAPAuth: username or password property is null or empty" ) ;
30
18
}
31
19
}
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
- }
42
20
}
43
21
}
You can’t perform that action at this time.
0 commit comments