Skip to content

Commit a98bcc3

Browse files
committed
Document how to use a custom authentication header e.g Kerberos (#3519)
* Document how to subclass the HttpConnection to provide authentication headers, e.g for Kerberos * move comment about examples to the top
1 parent 2a6d098 commit a98bcc3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Tests/Tests/ClientConcepts/Connection/ModifyingDefaultConnection.doc.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
using Tests.Core.Extensions;
1212
using Tests.Domain;
1313
using Tests.Framework;
14+
#if DOTNETCORE
15+
using System.Net.Http;
16+
using System.Net.Http.Headers;
17+
#endif
1418

1519
namespace Tests.ClientConcepts.Connection
1620
{
@@ -117,6 +121,7 @@ public void InMemoryConnectionOverloadedCtor()
117121
* By deriving from `HttpConnection`, it is possible to change the behaviour of the connection. The following
118122
* provides some examples
119123
*
124+
*
120125
* [[servicepoint-behaviour]]
121126
* ===== ServicePoint behaviour
122127
*
@@ -180,5 +185,30 @@ public void UseX509CertificateHttpConnection()
180185
* See <<working-with-certificates, Working with certificates>> for further details.
181186
*/
182187
#endif
188+
#if DOTNETCORE
189+
/*
190+
* [[kerberos-authentication]]
191+
* ===== Kerberos Authentication
192+
*
193+
* For a lot of use cases subclassing HttpConnection is a great way to customize the http connection for your needs.
194+
* E.g if you want to authenticate with Kerberos, creating a custom HttpConnection as followed allows you to set the right HTTP headers.
195+
*
196+
*
197+
* TIP use something like https://www.nuget.org/packages/Kerberos.NET/ to fill in the actual blanks of this implementation
198+
*/
199+
public class KerberosConnection : HttpConnection
200+
{
201+
protected override HttpRequestMessage CreateRequestMessage(RequestData requestData)
202+
{
203+
var message = base.CreateRequestMessage(requestData);
204+
var header = string.Empty;
205+
message.Headers.Authorization = new AuthenticationHeaderValue("Negotiate", header);
206+
return message;
207+
}
208+
}
209+
#endif
210+
211+
212+
183213
}
184214
}

0 commit comments

Comments
 (0)