diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index f4d59a6..0000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -#------------------------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. -#------------------------------------------------------------------------------------------------------------- - -FROM mcr.microsoft.com/dotnet/core/sdk:2.1 - -# Avoid warnings by switching to noninteractive -ENV DEBIAN_FRONTEND=noninteractive - -# Or your actual UID, GID on Linux if not the default 1000 -ARG USERNAME=vscode -ARG USER_UID=1000 -ARG USER_GID=$USER_UID - -# Configure apt and install packages -RUN apt-get update \ - && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ - # - # Verify git, process tools, lsb-release (common in install instructions for CLIs) installed - && apt-get -y install git procps lsb-release \ - # - # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user. - && groupadd --gid $USER_GID $USERNAME \ - && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \ - # [Optional] Uncomment the next three lines to add sudo support - # && apt-get install -y sudo \ - # && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ - # && chmod 0440 /etc/sudoers.d/$USERNAME \ - # - # Clean up - && apt-get autoremove -y \ - && apt-get clean -y \ - && rm -rf /var/lib/apt/lists/* - -# Switch back to dialog for any ad-hoc use of apt-get -ENV DEBIAN_FRONTEND= \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 26e650d..0000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,22 +0,0 @@ -// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at -// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/dotnetcore-2.1 -{ - "name": "C# (.NET Core 2.1)", - "dockerFile": "Dockerfile", - - // Uncomment the next line if you want to publish any ports. - // "appPort": [], - - // Uncomment the next line if you want to add in default container specific settings.json values - // "settings": { "workbench.colorTheme": "Quiet Light" }, - - // Uncomment the next line to run commands after the container is created. - // "postCreateCommand": "dotnet restore" - - // Uncomment the next line to use a non-root user. See https://aka.ms/vscode-remote/containers/non-root-user. - // "runArgs": [ "-u", "1000" ], - - "extensions": [ - "ms-vscode.csharp" - ] -} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 4032327..a4d9b21 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -24,5 +24,5 @@ "request": "attach", "processId": "${command:pickProcess}" } - ,] + ] } \ No newline at end of file diff --git a/Patros.AuthenticatedHttpClient.AuthorizationHeader/AuthorizationHeaderAuthenticatedHttpClient.cs b/Patros.AuthenticatedHttpClient.AuthorizationHeader/AuthorizationHeaderAuthenticatedHttpClient.cs index b901150..1b561e8 100644 --- a/Patros.AuthenticatedHttpClient.AuthorizationHeader/AuthorizationHeaderAuthenticatedHttpClient.cs +++ b/Patros.AuthenticatedHttpClient.AuthorizationHeader/AuthorizationHeaderAuthenticatedHttpClient.cs @@ -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); diff --git a/Patros.AuthenticatedHttpClient.AuthorizationHeader/AuthorizationHeaderAuthenticatedHttpMessageHandler.cs b/Patros.AuthenticatedHttpClient.AuthorizationHeader/AuthorizationHeaderAuthenticatedHttpMessageHandler.cs index 183ed14..2352c75 100644 --- a/Patros.AuthenticatedHttpClient.AuthorizationHeader/AuthorizationHeaderAuthenticatedHttpMessageHandler.cs +++ b/Patros.AuthenticatedHttpClient.AuthorizationHeader/AuthorizationHeaderAuthenticatedHttpMessageHandler.cs @@ -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) { diff --git a/Patros.AuthenticatedHttpClient.AzureAd.Tests/AzureAdAuthenticatedHttpClientTests.cs b/Patros.AuthenticatedHttpClient.AzureAd.Tests/AzureAdAuthenticatedHttpClientTests.cs index bfffdd6..b339365 100644 --- a/Patros.AuthenticatedHttpClient.AzureAd.Tests/AzureAdAuthenticatedHttpClientTests.cs +++ b/Patros.AuthenticatedHttpClient.AzureAd.Tests/AzureAdAuthenticatedHttpClientTests.cs @@ -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(); } diff --git a/Patros.AuthenticatedHttpClient.AzureAd/AzureAdAuthenticatedHttpClient.cs b/Patros.AuthenticatedHttpClient.AzureAd/AzureAdAuthenticatedHttpClient.cs index 8992570..61b3bfa 100644 --- a/Patros.AuthenticatedHttpClient.AzureAd/AzureAdAuthenticatedHttpClient.cs +++ b/Patros.AuthenticatedHttpClient.AzureAd/AzureAdAuthenticatedHttpClient.cs @@ -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); diff --git a/Patros.AuthenticatedHttpClient.AzureAd/AzureAdAuthenticatedHttpMessageHandler.cs b/Patros.AuthenticatedHttpClient.AzureAd/AzureAdAuthenticatedHttpMessageHandler.cs index a7c4518..dd7b990 100644 --- a/Patros.AuthenticatedHttpClient.AzureAd/AzureAdAuthenticatedHttpMessageHandler.cs +++ b/Patros.AuthenticatedHttpClient.AzureAd/AzureAdAuthenticatedHttpMessageHandler.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Net.Http; using System.Net.Http.Headers; using System.Globalization; @@ -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) { diff --git a/Patros.AuthenticatedHttpClient.AzureAppServiceManagedIdentity.Tests/AzureAppSericeManagedIdentityAuthenticatedHttpClientTests.cs b/Patros.AuthenticatedHttpClient.AzureAppServiceManagedIdentity.Tests/AzureAppSericeManagedIdentityAuthenticatedHttpClientTests.cs index ec9f3e7..d24adfe 100644 --- a/Patros.AuthenticatedHttpClient.AzureAppServiceManagedIdentity.Tests/AzureAppSericeManagedIdentityAuthenticatedHttpClientTests.cs +++ b/Patros.AuthenticatedHttpClient.AzureAppServiceManagedIdentity.Tests/AzureAppSericeManagedIdentityAuthenticatedHttpClientTests.cs @@ -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(); } diff --git a/Patros.AuthenticatedHttpClient.AzureAppServiceManagedIdentity/AzureAppServiceManagedIdentityAuthenticatedHttpClient.cs b/Patros.AuthenticatedHttpClient.AzureAppServiceManagedIdentity/AzureAppServiceManagedIdentityAuthenticatedHttpClient.cs index c401110..45d76a7 100644 --- a/Patros.AuthenticatedHttpClient.AzureAppServiceManagedIdentity/AzureAppServiceManagedIdentityAuthenticatedHttpClient.cs +++ b/Patros.AuthenticatedHttpClient.AzureAppServiceManagedIdentity/AzureAppServiceManagedIdentityAuthenticatedHttpClient.cs @@ -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); diff --git a/Patros.AuthenticatedHttpClient.Basic.Tests/BasicAuthenticatedHttpClientTests.cs b/Patros.AuthenticatedHttpClient.Basic.Tests/BasicAuthenticatedHttpClientTests.cs index 16ec027..9371f55 100644 --- a/Patros.AuthenticatedHttpClient.Basic.Tests/BasicAuthenticatedHttpClientTests.cs +++ b/Patros.AuthenticatedHttpClient.Basic.Tests/BasicAuthenticatedHttpClientTests.cs @@ -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(); } diff --git a/Patros.AuthenticatedHttpClient.Basic/BasicAuthenticatedHttpClient.cs b/Patros.AuthenticatedHttpClient.Basic/BasicAuthenticatedHttpClient.cs index cf18969..ca08ecb 100644 --- a/Patros.AuthenticatedHttpClient.Basic/BasicAuthenticatedHttpClient.cs +++ b/Patros.AuthenticatedHttpClient.Basic/BasicAuthenticatedHttpClient.cs @@ -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); diff --git a/Patros.AuthenticatedHttpClient.Basic/BasicAuthenticatedHttpMessageHandler.cs b/Patros.AuthenticatedHttpClient.Basic/BasicAuthenticatedHttpMessageHandler.cs index 4a98ccf..9aeec37 100644 --- a/Patros.AuthenticatedHttpClient.Basic/BasicAuthenticatedHttpMessageHandler.cs +++ b/Patros.AuthenticatedHttpClient.Basic/BasicAuthenticatedHttpMessageHandler.cs @@ -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) { diff --git a/Patros.AuthenticatedHttpClient.CustomHeader/CustomHeaderAuthenticatedHttpClient.cs b/Patros.AuthenticatedHttpClient.CustomHeader/CustomHeaderAuthenticatedHttpClient.cs index 914a766..ce8b08e 100644 --- a/Patros.AuthenticatedHttpClient.CustomHeader/CustomHeaderAuthenticatedHttpClient.cs +++ b/Patros.AuthenticatedHttpClient.CustomHeader/CustomHeaderAuthenticatedHttpClient.cs @@ -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."); diff --git a/Patros.AuthenticatedHttpClient.QueryStringParameter.Tests/QueryStringParameterAuthenticatedHttpClientTests.cs b/Patros.AuthenticatedHttpClient.QueryStringParameter.Tests/QueryStringParameterAuthenticatedHttpClientTests.cs index 5bb9a57..129fb89 100644 --- a/Patros.AuthenticatedHttpClient.QueryStringParameter.Tests/QueryStringParameterAuthenticatedHttpClientTests.cs +++ b/Patros.AuthenticatedHttpClient.QueryStringParameter.Tests/QueryStringParameterAuthenticatedHttpClientTests.cs @@ -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(); } @@ -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(); } @@ -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(); } diff --git a/Patros.AuthenticatedHttpClient.QueryStringParameter/QueryStringParameterAuthenticatedHttpClient.cs b/Patros.AuthenticatedHttpClient.QueryStringParameter/QueryStringParameterAuthenticatedHttpClient.cs index 1916f26..2d6fd92 100644 --- a/Patros.AuthenticatedHttpClient.QueryStringParameter/QueryStringParameterAuthenticatedHttpClient.cs +++ b/Patros.AuthenticatedHttpClient.QueryStringParameter/QueryStringParameterAuthenticatedHttpClient.cs @@ -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."); diff --git a/README.md b/README.md index b1f12e8..596fbde 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ work too. Authorization Header Authenticated Http Client Example Usage ------------------------------------------------------------ -``` +```shell dotnet add package Patros.AuthenticatedHttpClient.AuthorizationHeader ``` @@ -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 ``` @@ -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 ``` @@ -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 ``` @@ -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 ``` @@ -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