@@ -154,11 +154,10 @@ public ConnectionSettingsBuilder UriSelector(IUriSelector uriSelector)
154154 return this ;
155155 }
156156
157- public ConnectionSettingsBuilder OAuth2Options ( OAuth2Options ? oAuth2Options = null )
157+ public ConnectionSettingsBuilder OAuth2Options ( OAuth2Options ? oAuth2Options )
158158 {
159159 _oAuth2Options = oAuth2Options ;
160160 return this ;
161-
162161 }
163162
164163 public ConnectionSettings Build ( )
@@ -171,26 +170,26 @@ public ConnectionSettings Build()
171170 _containerId , _saslMechanism ,
172171 _recoveryConfiguration ,
173172 _maxFrameSize ,
174- _tlsSettings ) ;
173+ _tlsSettings ,
174+ _oAuth2Options ) ;
175175 }
176- else if ( _uris is not null )
176+
177+ if ( _uris is not null )
177178 {
178179 return new ClusterConnectionSettings ( _uris ,
179180 _uriSelector ,
180181 _containerId , _saslMechanism ,
181182 _recoveryConfiguration ,
182183 _maxFrameSize ,
183- _tlsSettings ) ;
184- }
185- else
186- {
187- return new ConnectionSettings ( _scheme , _host , _port , _user ,
188- _password , _virtualHost ,
189- _containerId , _saslMechanism ,
190- _recoveryConfiguration ,
191- _maxFrameSize ,
192- _tlsSettings ) ;
184+ _tlsSettings , _oAuth2Options ) ;
193185 }
186+
187+ return new ConnectionSettings ( _scheme , _host , _port , _user ,
188+ _password , _virtualHost ,
189+ _containerId , _saslMechanism ,
190+ _recoveryConfiguration ,
191+ _maxFrameSize ,
192+ _tlsSettings , _oAuth2Options ) ;
194193 }
195194
196195 private void ValidateUris ( )
@@ -214,14 +213,14 @@ public class ConnectionSettings : IEquatable<ConnectionSettings>
214213 private readonly TlsSettings ? _tlsSettings ;
215214 private readonly SaslMechanism _saslMechanism = SaslMechanism . Plain ;
216215 private readonly IRecoveryConfiguration _recoveryConfiguration = new RecoveryConfiguration ( ) ;
217- private readonly OAuth2Options ? _oAuth2Options = null ;
218216
219217 public ConnectionSettings ( Uri uri ,
220218 string ? containerId = null ,
221219 SaslMechanism ? saslMechanism = null ,
222220 IRecoveryConfiguration ? recoveryConfiguration = null ,
223221 uint ? maxFrameSize = null ,
224- TlsSettings ? tlsSettings = null )
222+ TlsSettings ? tlsSettings = null ,
223+ OAuth2Options ? oAuth2Options = null )
225224 : this ( containerId , saslMechanism , recoveryConfiguration , maxFrameSize , tlsSettings )
226225 {
227226 ( string ? user , string ? password ) = ProcessUserInfo ( uri ) ;
@@ -241,6 +240,14 @@ public ConnectionSettings(Uri uri,
241240 path : "/" ,
242241 scheme : scheme ) ;
243242
243+ if ( oAuth2Options is not null )
244+ {
245+ // in case of OAuth2, we need to use plain mechanism
246+ _saslMechanism = SaslMechanism . Plain ;
247+ _address = new Address ( _address . Host , _address . Port , "" , oAuth2Options . Token , _address . Path ,
248+ _address . Scheme ) ;
249+ }
250+
244251 _tlsSettings = InitTlsSettings ( ) ;
245252 }
246253
@@ -254,7 +261,8 @@ public ConnectionSettings(string scheme,
254261 SaslMechanism ? saslMechanism = null ,
255262 IRecoveryConfiguration ? recoveryConfiguration = null ,
256263 uint ? maxFrameSize = null ,
257- TlsSettings ? tlsSettings = null )
264+ TlsSettings ? tlsSettings = null ,
265+ OAuth2Options ? oAuth2Options = null )
258266 : this ( containerId , saslMechanism , recoveryConfiguration , maxFrameSize , tlsSettings )
259267 {
260268 if ( false == Utils . IsValidScheme ( scheme ) )
@@ -274,6 +282,14 @@ public ConnectionSettings(string scheme,
274282 _virtualHost = virtualHost ;
275283 }
276284
285+ if ( oAuth2Options is not null )
286+ {
287+ // in case of OAuth2, we need to use plain mechanism
288+ _saslMechanism = SaslMechanism . Plain ;
289+ _address = new Address ( _address . Host , _address . Port , "" , oAuth2Options . Token , _address . Path ,
290+ _address . Scheme ) ;
291+ }
292+
277293 _tlsSettings = InitTlsSettings ( ) ;
278294 }
279295
@@ -282,8 +298,7 @@ protected ConnectionSettings(
282298 SaslMechanism ? saslMechanism = null ,
283299 IRecoveryConfiguration ? recoveryConfiguration = null ,
284300 uint ? maxFrameSize = null ,
285- TlsSettings ? tlsSettings = null ,
286- OAuth2Options ? oAuth2Options = null )
301+ TlsSettings ? tlsSettings = null )
287302 {
288303 if ( containerId is not null )
289304 {
@@ -300,15 +315,6 @@ protected ConnectionSettings(
300315 _recoveryConfiguration = recoveryConfiguration ;
301316 }
302317
303- _oAuth2Options = oAuth2Options ;
304- if ( _oAuth2Options is not null )
305- {
306- // in case of OAuth2, we need to use plain mechanism
307- _saslMechanism = SaslMechanism . Plain ;
308- _address = new Address ( _address . Host , _address . Port , _address . User , _oAuth2Options . Token , _address . Path ,
309- _address . Scheme ) ;
310- }
311-
312318 if ( maxFrameSize is not null )
313319 {
314320 _maxFrameSize = ( uint ) maxFrameSize ;
@@ -477,7 +483,7 @@ public ClusterConnectionSettings(IEnumerable<Uri> uris,
477483 uint ? maxFrameSize = null ,
478484 TlsSettings ? tlsSettings = null ,
479485 OAuth2Options ? oAuth2Options = null )
480- : base ( containerId , saslMechanism , recoveryConfiguration , maxFrameSize , tlsSettings , oAuth2Options )
486+ : base ( containerId , saslMechanism , recoveryConfiguration , maxFrameSize , tlsSettings )
481487 {
482488 _uris = uris . ToList ( ) ;
483489 if ( _uris . Count == 0 )
@@ -526,6 +532,14 @@ public ClusterConnectionSettings(IEnumerable<Uri> uris,
526532 path : "/" ,
527533 scheme : scheme ) ;
528534
535+ // if (oAuth2Options is not null)
536+ // {
537+ // // in case of OAuth2, we need to use plain mechanism
538+ // _saslMechanism = SaslMechanism.Plain;
539+ // _address = new Address(_address.Host, _address.Port, "", oAuth2Options.Token, _address.Path,
540+ // _address.Scheme);
541+ // }
542+
529543 _uriToAddress [ uri ] = address ;
530544
531545 if ( first )
0 commit comments