Skip to content

Commit ba0c73e

Browse files
[csharp] [Req#15932] Added support for windows authentication by exposing UseDefaultCredentials property (#15935)
* Added support for windows authentication by exposing UseDefaultCredentials property * Updated samples and docs * update doc, samples --------- Co-authored-by: William Cheng <wing328hk@gmail.com>
1 parent 117e511 commit ba0c73e

31 files changed

Lines changed: 245 additions & 29 deletions

File tree

modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ namespace {{packageName}}.Client
454454
CookieContainer = cookies,
455455
MaxTimeout = configuration.Timeout,
456456
Proxy = configuration.Proxy,
457-
UserAgent = configuration.UserAgent
457+
UserAgent = configuration.UserAgent,
458+
UseDefaultCredentials = configuration.UseDefaultCredentials
458459
};
459460
460461
RestClient client = new RestClient(clientOptions)
@@ -566,7 +567,8 @@ namespace {{packageName}}.Client
566567
ClientCertificates = configuration.ClientCertificates,
567568
MaxTimeout = configuration.Timeout,
568569
Proxy = configuration.Proxy,
569-
UserAgent = configuration.UserAgent
570+
UserAgent = configuration.UserAgent,
571+
UseDefaultCredentials = configuration.UseDefaultCredentials
570572
};
571573
572574
RestClient client = new RestClient(clientOptions)

modules/openapi-generator/src/main/resources/csharp/Configuration.mustache

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ namespace {{packageName}}.Client
7575
/// </summary>
7676
private string _basePath;
7777

78+
private bool _useDefaultCredentials = false;
79+
7880
/// <summary>
7981
/// Gets or sets the API key based on the authentication name.
8082
/// This is the key and value comprising the "secret" for accessing an API.
@@ -246,11 +248,21 @@ namespace {{packageName}}.Client
246248
/// <summary>
247249
/// Gets or sets the base path for API access.
248250
/// </summary>
249-
public virtual string BasePath {
251+
public virtual string BasePath
252+
{
250253
get { return _basePath; }
251254
set { _basePath = value; }
252255
}
253256

257+
/// <summary>
258+
/// Determine whether or not the "default credentials" (e.g. the user account under which the current process is running) will be sent along to the server. The default is false.
259+
/// </summary>
260+
public virtual bool UseDefaultCredentials
261+
{
262+
get { return _useDefaultCredentials; }
263+
set { _useDefaultCredentials = value; }
264+
}
265+
254266
/// <summary>
255267
/// Gets or sets the default header.
256268
/// </summary>
@@ -702,6 +714,7 @@ namespace {{packageName}}.Client
702714
TempFolderPath = second.TempFolderPath ?? first.TempFolderPath,
703715
DateTimeFormat = second.DateTimeFormat ?? first.DateTimeFormat,
704716
ClientCertificates = second.ClientCertificates ?? first.ClientCertificates,
717+
UseDefaultCredentials = second.UseDefaultCredentials
705718
};
706719
return config;
707720
}

modules/openapi-generator/src/main/resources/csharp/IReadableConfiguration.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ namespace {{packageName}}.Client
123123
/// <value>Password.</value>
124124
string Password { get; }
125125

126+
/// <summary>
127+
/// Determine whether or not the "default credentials" (e.g. the user account under which the current process is running) will be sent along to the server. The default is false.
128+
/// </summary>
129+
bool UseDefaultCredentials { get; }
130+
126131
/// <summary>
127132
/// Get the servers associated with the operation.
128133
/// </summary>

samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Client/ApiClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ private ApiResponse<T> Exec<T>(RestRequest req, RequestOptions options, IReadabl
453453
CookieContainer = cookies,
454454
MaxTimeout = configuration.Timeout,
455455
Proxy = configuration.Proxy,
456-
UserAgent = configuration.UserAgent
456+
UserAgent = configuration.UserAgent,
457+
UseDefaultCredentials = configuration.UseDefaultCredentials
457458
};
458459

459460
RestClient client = new RestClient(clientOptions)
@@ -548,7 +549,8 @@ private ApiResponse<T> Exec<T>(RestRequest req, RequestOptions options, IReadabl
548549
ClientCertificates = configuration.ClientCertificates,
549550
MaxTimeout = configuration.Timeout,
550551
Proxy = configuration.Proxy,
551-
UserAgent = configuration.UserAgent
552+
UserAgent = configuration.UserAgent,
553+
UseDefaultCredentials = configuration.UseDefaultCredentials
552554
};
553555

554556
RestClient client = new RestClient(clientOptions)

samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Client/Configuration.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public class Configuration : IReadableConfiguration
7070
/// </summary>
7171
private string _basePath;
7272

73+
private bool _useDefaultCredentials = false;
74+
7375
/// <summary>
7476
/// Gets or sets the API key based on the authentication name.
7577
/// This is the key and value comprising the "secret" for accessing an API.
@@ -175,11 +177,21 @@ public Configuration(
175177
/// <summary>
176178
/// Gets or sets the base path for API access.
177179
/// </summary>
178-
public virtual string BasePath {
180+
public virtual string BasePath
181+
{
179182
get { return _basePath; }
180183
set { _basePath = value; }
181184
}
182185

186+
/// <summary>
187+
/// Determine whether or not the "default credentials" (e.g. the user account under which the current process is running) will be sent along to the server. The default is false.
188+
/// </summary>
189+
public virtual bool UseDefaultCredentials
190+
{
191+
get { return _useDefaultCredentials; }
192+
set { _useDefaultCredentials = value; }
193+
}
194+
183195
/// <summary>
184196
/// Gets or sets the default header.
185197
/// </summary>
@@ -579,6 +591,7 @@ public static IReadableConfiguration MergeConfigurations(IReadableConfiguration
579591
TempFolderPath = second.TempFolderPath ?? first.TempFolderPath,
580592
DateTimeFormat = second.DateTimeFormat ?? first.DateTimeFormat,
581593
ClientCertificates = second.ClientCertificates ?? first.ClientCertificates,
594+
UseDefaultCredentials = second.UseDefaultCredentials
582595
};
583596
return config;
584597
}

samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Client/IReadableConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public interface IReadableConfiguration
9999
/// <value>Password.</value>
100100
string Password { get; }
101101

102+
/// <summary>
103+
/// Determine whether or not the "default credentials" (e.g. the user account under which the current process is running) will be sent along to the server. The default is false.
104+
/// </summary>
105+
bool UseDefaultCredentials { get; }
106+
102107
/// <summary>
103108
/// Get the servers associated with the operation.
104109
/// </summary>

samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/ApiClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ private ApiResponse<T> Exec<T>(RestRequest req, RequestOptions options, IReadabl
454454
CookieContainer = cookies,
455455
MaxTimeout = configuration.Timeout,
456456
Proxy = configuration.Proxy,
457-
UserAgent = configuration.UserAgent
457+
UserAgent = configuration.UserAgent,
458+
UseDefaultCredentials = configuration.UseDefaultCredentials
458459
};
459460

460461
RestClient client = new RestClient(clientOptions)
@@ -563,7 +564,8 @@ private ApiResponse<T> Exec<T>(RestRequest req, RequestOptions options, IReadabl
563564
ClientCertificates = configuration.ClientCertificates,
564565
MaxTimeout = configuration.Timeout,
565566
Proxy = configuration.Proxy,
566-
UserAgent = configuration.UserAgent
567+
UserAgent = configuration.UserAgent,
568+
UseDefaultCredentials = configuration.UseDefaultCredentials
567569
};
568570

569571
RestClient client = new RestClient(clientOptions)

samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/Configuration.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public class Configuration : IReadableConfiguration
7171
/// </summary>
7272
private string _basePath;
7373

74+
private bool _useDefaultCredentials = false;
75+
7476
/// <summary>
7577
/// Gets or sets the API key based on the authentication name.
7678
/// This is the key and value comprising the "secret" for accessing an API.
@@ -276,11 +278,21 @@ public Configuration(
276278
/// <summary>
277279
/// Gets or sets the base path for API access.
278280
/// </summary>
279-
public virtual string BasePath {
281+
public virtual string BasePath
282+
{
280283
get { return _basePath; }
281284
set { _basePath = value; }
282285
}
283286

287+
/// <summary>
288+
/// Determine whether or not the "default credentials" (e.g. the user account under which the current process is running) will be sent along to the server. The default is false.
289+
/// </summary>
290+
public virtual bool UseDefaultCredentials
291+
{
292+
get { return _useDefaultCredentials; }
293+
set { _useDefaultCredentials = value; }
294+
}
295+
284296
/// <summary>
285297
/// Gets or sets the default header.
286298
/// </summary>
@@ -718,6 +730,7 @@ public static IReadableConfiguration MergeConfigurations(IReadableConfiguration
718730
TempFolderPath = second.TempFolderPath ?? first.TempFolderPath,
719731
DateTimeFormat = second.DateTimeFormat ?? first.DateTimeFormat,
720732
ClientCertificates = second.ClientCertificates ?? first.ClientCertificates,
733+
UseDefaultCredentials = second.UseDefaultCredentials
721734
};
722735
return config;
723736
}

samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/IReadableConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ public interface IReadableConfiguration
124124
/// <value>Password.</value>
125125
string Password { get; }
126126

127+
/// <summary>
128+
/// Determine whether or not the "default credentials" (e.g. the user account under which the current process is running) will be sent along to the server. The default is false.
129+
/// </summary>
130+
bool UseDefaultCredentials { get; }
131+
127132
/// <summary>
128133
/// Get the servers associated with the operation.
129134
/// </summary>

samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/Configuration.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public class Configuration : IReadableConfiguration
7070
/// </summary>
7171
private string _basePath;
7272

73+
private bool _useDefaultCredentials = false;
74+
7375
/// <summary>
7476
/// Gets or sets the API key based on the authentication name.
7577
/// This is the key and value comprising the "secret" for accessing an API.
@@ -275,11 +277,21 @@ public Configuration(
275277
/// <summary>
276278
/// Gets or sets the base path for API access.
277279
/// </summary>
278-
public virtual string BasePath {
280+
public virtual string BasePath
281+
{
279282
get { return _basePath; }
280283
set { _basePath = value; }
281284
}
282285

286+
/// <summary>
287+
/// Determine whether or not the "default credentials" (e.g. the user account under which the current process is running) will be sent along to the server. The default is false.
288+
/// </summary>
289+
public virtual bool UseDefaultCredentials
290+
{
291+
get { return _useDefaultCredentials; }
292+
set { _useDefaultCredentials = value; }
293+
}
294+
283295
/// <summary>
284296
/// Gets or sets the default header.
285297
/// </summary>
@@ -689,6 +701,7 @@ public static IReadableConfiguration MergeConfigurations(IReadableConfiguration
689701
TempFolderPath = second.TempFolderPath ?? first.TempFolderPath,
690702
DateTimeFormat = second.DateTimeFormat ?? first.DateTimeFormat,
691703
ClientCertificates = second.ClientCertificates ?? first.ClientCertificates,
704+
UseDefaultCredentials = second.UseDefaultCredentials
692705
};
693706
return config;
694707
}

0 commit comments

Comments
 (0)