@@ -16,22 +16,43 @@ public abstract class SSPIContextProvider
16
16
private protected TdsParserStateObject _physicalStateObj = null ! ;
17
17
private string [ ] _serverNames = Array . Empty < string > ( ) ;
18
18
19
- internal void Initialize ( ServerInfo serverInfo , TdsParserStateObject physicalStateObj , TdsParser parser , string [ ] serverNames )
19
+ internal void Initialize ( ServerInfo serverInfo , TdsParserStateObject physicalStateObj , TdsParser parser , string [ ] serverNames , SqlInternalConnectionTds connection )
20
20
{
21
21
_parser = parser ;
22
22
_physicalStateObj = physicalStateObj ;
23
23
_serverInfo = serverInfo ;
24
24
_serverNames = serverNames ;
25
+ AuthenticationParameters = InitializeAuthenticationParameters ( connection ) ;
25
26
26
27
Debug . Assert ( _serverNames . Length > 0 ) ;
27
28
28
29
Initialize ( ) ;
29
30
}
30
31
32
+ private SqlAuthenticationParameters InitializeAuthenticationParameters ( SqlInternalConnectionTds connection )
33
+ {
34
+ var auth = new SqlAuthenticationParameters . Builder ( connection . ConnectionOptions . Authentication , "resource" , "auth" , connection . ConnectionOptions . ObtainWorkstationId ( ) , connection . ConnectionOptions . InitialCatalog ) ;
35
+
36
+ if ( connection . ConnectionOptions . UserID is { } userId )
37
+ {
38
+ auth . WithUserId ( userId ) ;
39
+ }
40
+
41
+ if ( connection . ConnectionOptions . Password is { } password )
42
+ {
43
+ auth . WithPassword ( password ) ;
44
+ }
45
+
46
+ return auth ;
47
+ }
48
+
31
49
private protected virtual void Initialize ( )
32
50
{
33
51
}
34
52
53
+ /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SSPIContextProvider.xml' path='docs/members[@name="SSPIContextProvider"]/AuthenticationParameters/*' />
54
+ public SqlAuthenticationParameters AuthenticationParameters { get ; private set ; } = null ! ;
55
+
35
56
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SSPIContextProvider.xml' path='docs/members[@name="SSPIContextProvider"]/ServerNames/*' />
36
57
public IReadOnlyList < string > ServerNames => _serverNames ;
37
58
0 commit comments