Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions .devcontainer/Dockerfile

This file was deleted.

22 changes: 0 additions & 22 deletions .devcontainer/devcontainer.json

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ namespace Patros.AuthenticatedHttpClient
{
public static class AuthorizationHeaderAuthenticatedHttpClient
{
public static HttpClient GetClient(AuthorizationHeaderAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler = null)
public static HttpClient GetClient(AuthorizationHeaderAuthenticatedHttpClientOptions options)
{
var msgHandler = new AuthorizationHeaderAuthenticatedHttpMessageHandler(options);
return new HttpClient(msgHandler);
}

public static HttpClient GetClient(AuthorizationHeaderAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler)
{
var msgHandler = new AuthorizationHeaderAuthenticatedHttpMessageHandler(options, innerHandler);
return new HttpClient(msgHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Patros.AuthenticatedHttpClient
{
public class AuthorizationHeaderAuthenticatedHttpMessageHandler : DelegatingHandler
{
private AuthenticationHeaderValue _authorizationHeader;
private readonly AuthenticationHeaderValue _authorizationHeader;

public AuthorizationHeaderAuthenticatedHttpMessageHandler(AuthorizationHeaderAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task TestRequestHasAuthorizationHeader()
mockMsgHandler.CallBase = true;
var client = new HttpClient(mockMsgHandler.Object);

var responseContent = await client.GetStringAsync("https://www.example.com");
await client.GetStringAsync("https://www.example.com");

mockHttp.VerifyNoOutstandingExpectation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ namespace Patros.AuthenticatedHttpClient
// https://github.com/Azure-Samples/active-directory-dotnet-daemon/blob/master/TodoListDaemon/Program.cs
public static class AzureAdAuthenticatedHttpClient
{
public static HttpClient GetClient(AzureAdAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler = null)
public static HttpClient GetClient(AzureAdAuthenticatedHttpClientOptions options)
{
var msgHandler = new AzureAdAuthenticatedHttpMessageHandler(options);
return new HttpClient(msgHandler);
}

public static HttpClient GetClient(AzureAdAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler)
{
var msgHandler = new AzureAdAuthenticatedHttpMessageHandler(options, innerHandler);
return new HttpClient(msgHandler);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Globalization;
Expand All @@ -14,7 +14,7 @@ public class AzureAdAuthenticatedHttpMessageHandler : DelegatingHandler
{
private string _resourceId;
private AuthenticationContext _authContext;
private ClientCredential _clientCredential;
private readonly ClientCredential _clientCredential;

public AzureAdAuthenticatedHttpMessageHandler(AzureAdAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task TestRequestHasAuthorizationHeader()
mockMsgHandler.CallBase = true;
var client = new HttpClient(mockMsgHandler.Object);

var responseContent = await client.GetStringAsync("https://www.example.com");
await client.GetStringAsync("https://www.example.com");

mockHttp.VerifyNoOutstandingExpectation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

namespace Patros.AuthenticatedHttpClient
{
public class AzureAppServiceManagedIdentityAuthenticatedHttpClient
public static class AzureAppServiceManagedIdentityAuthenticatedHttpClient
{
public static HttpClient GetClient(AzureAppServiceManagedIdentityAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler = null)
public static HttpClient GetClient(AzureAppServiceManagedIdentityAuthenticatedHttpClientOptions options)
{
var msgHandler = new AzureAppServiceManagedIdentityAuthenticatedHttpMessageHandler(options);
return new HttpClient(msgHandler);
}

public static HttpClient GetClient(AzureAppServiceManagedIdentityAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler)
{
var msgHandler = new AzureAppServiceManagedIdentityAuthenticatedHttpMessageHandler(options, innerHandler);
return new HttpClient(msgHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task TestRequestHasAuthorizationHeader()
Password = "open sesame"
}, mockHttp);

var responseContent = await client.GetStringAsync("https://www.example.com");
await client.GetStringAsync("https://www.example.com");

mockHttp.VerifyNoOutstandingExpectation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ namespace Patros.AuthenticatedHttpClient
{
public static class BasicAuthenticatedHttpClient
{
public static HttpClient GetClient(BasicAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler = null)
public static HttpClient GetClient(BasicAuthenticatedHttpClientOptions options)
{
var msgHandler = new BasicAuthenticatedHttpMessageHandler(options);
return new HttpClient(msgHandler);
}

public static HttpClient GetClient(BasicAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler)
{
var msgHandler = new BasicAuthenticatedHttpMessageHandler(options, innerHandler);
return new HttpClient(msgHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Patros.AuthenticatedHttpClient
{
public class BasicAuthenticatedHttpMessageHandler : DelegatingHandler
{
private AuthenticationHeaderValue _authorizationHeader;
private readonly AuthenticationHeaderValue _authorizationHeader;

public BasicAuthenticatedHttpMessageHandler(BasicAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ namespace Patros.AuthenticatedHttpClient
{
public static class CustomHeaderAuthenticatedHttpClient
{
public static HttpClient GetClient(CustomHeaderAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler = null)
public static HttpClient GetClient(CustomHeaderAuthenticatedHttpClientOptions options)
{
var msgHandler = new CustomHeaderAuthenticatedHttpMessageHandler(options);
return new HttpClient(msgHandler);
}

public static HttpClient GetClient(CustomHeaderAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler)
{
var msgHandler = new CustomHeaderAuthenticatedHttpMessageHandler(options, innerHandler);
return new HttpClient(msgHandler);
}

public static HttpClient GetClient(MultipleCustomHeaderAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler = null)
public static HttpClient GetClient(MultipleCustomHeaderAuthenticatedHttpClientOptions options)
{
return GetClient(options, null);
}

public static HttpClient GetClient(MultipleCustomHeaderAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler)
{
if (options.Headers.Count == 0) throw new ArgumentOutOfRangeException(nameof(options), "No headers supplied.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task TestRequestReplacesAuthenticationParameter()
Value = "test-value"
}, mockHttp);

var responseContent = await client.GetStringAsync("https://www.example.com?test-name=incorrect-value");
await client.GetStringAsync("https://www.example.com?test-name=incorrect-value");

mockHttp.VerifyNoOutstandingExpectation();
}
Expand All @@ -89,7 +89,7 @@ public async Task TestRequestAddsAuthenticationParameterToExistingQuery()
Value = "test-value"
}, mockHttp);

var responseContent = await client.GetStringAsync("https://www.example.com?other-name=other-value");
await client.GetStringAsync("https://www.example.com?other-name=other-value");

mockHttp.VerifyNoOutstandingExpectation();
}
Expand All @@ -114,7 +114,7 @@ public async Task TestMultipleParameterRequestAddsAuthenticationParameters()
}
}, mockHttp);

var responseContent = await client.GetStringAsync("https://www.example.com");
await client.GetStringAsync("https://www.example.com");

mockHttp.VerifyNoOutstandingExpectation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ namespace Patros.AuthenticatedHttpClient
{
public static class QueryStringParameterAuthenticatedHttpClient
{
public static HttpClient GetClient(QueryStringParameterAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler = null)
public static HttpClient GetClient(QueryStringParameterAuthenticatedHttpClientOptions options)
{
var msgHandler = new QueryStringParameterAuthenticatedHttpMessageHandler(options);
return new HttpClient(msgHandler);
}

public static HttpClient GetClient(QueryStringParameterAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler)
{
var msgHandler = new QueryStringParameterAuthenticatedHttpMessageHandler(options, innerHandler);
return new HttpClient(msgHandler);
}

public static HttpClient GetClient(MultipleQueryStringParameterAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler = null)
public static HttpClient GetClient(MultipleQueryStringParameterAuthenticatedHttpClientOptions options)
{
return GetClient(options, null);
}

public static HttpClient GetClient(MultipleQueryStringParameterAuthenticatedHttpClientOptions options, HttpMessageHandler innerHandler)
{
if (options.Parameters.Count == 0) throw new ArgumentOutOfRangeException(nameof(options), "No parameters supplied.");

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ work too.
Authorization Header Authenticated Http Client Example Usage
------------------------------------------------------------

```
```shell
dotnet add package Patros.AuthenticatedHttpClient.AuthorizationHeader
```

Expand Down Expand Up @@ -86,7 +86,7 @@ var content = await client.GetStringAsync("https://www.example.com");
Azure App Service Managed Identity Authenticated Http Client Example Usage
--------------------------------------------------------------------------

```
```shell
dotnet add package Patros.AuthenticatedHttpClient.AzureAppServiceManagedIdentity
```

Expand All @@ -108,7 +108,7 @@ var content = await client.GetStringAsync("https://www.example.com");
Basic Authenticated Http Client Example Usage
---------------------------------------------

```
```shell
dotnet add package Patros.AuthenticatedHttpClient.Basic
```

Expand All @@ -131,7 +131,7 @@ var content = await client.GetStringAsync("https://www.example.com");
Custom Header Authenticated Http Client Example Usage
-----------------------------------------------------

```
```shell
dotnet add package Patros.AuthenticatedHttpClient.CustomHeader
```

Expand Down Expand Up @@ -177,7 +177,7 @@ var content = await client.GetStringAsync("https://www.example.com");
Query String Parameter Authenticated Http Client Example Usage
--------------------------------------------------------------

```
```shell
dotnet add package Patros.AuthenticatedHttpClient.QueryStringParameter
```

Expand Down Expand Up @@ -228,7 +228,7 @@ multiple authentication methods. Just for an example, let's pretend it
requires basic authentication, a query string parameter and a custom HTTP
header. I know, that would never happen in the real world... oh wait... there's the [Whispir API](https://whispir.github.io/api/).

```
```shell
dotnet add package Patros.AuthenticatedHttpClient.Basic
dotnet add package Patros.AuthenticatedHttpClient.CustomHeader
dotnet add package Patros.AuthenticatedHttpClient.QueryStringParameter
Expand Down