diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 543dc28..638d89d 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -71,7 +71,7 @@ jobs: CoverletOutputFormat: 'opencover' # https://github.com/microsoft/vstest/issues/4014#issuecomment-1307913682 shell: pwsh run: | - ./.sonar/scanner/dotnet-sonarscanner begin /k:"microsoft_kiota-authentication-azure-dotnet" /o:"microsoft" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="Microsoft.Kiota.Authentication.Azure.Tests/coverage.opencover.xml" + ./.sonar/scanner/dotnet-sonarscanner begin /k:"microsoft_kiota-authentication-azure-dotnet" /o:"microsoft" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="Microsoft.Kiota.Authentication.Azure.Tests/coverage.net6.0.opencover.xml" dotnet workload restore dotnet build dotnet test Microsoft.Kiota.Authentication.Azure.sln --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover diff --git a/CHANGELOG.md b/CHANGELOG.md index f32cd0b..3352856 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +## [1.1.1] - 2023-11-03 + +### Added + +- Allow http scheme on localhost. + ## [1.1.0] - 2023-10-23 ### Added diff --git a/Microsoft.Kiota.Authentication.Azure.Tests/AzureIdentityAuthenticationProviderTests.cs b/Microsoft.Kiota.Authentication.Azure.Tests/AzureIdentityAuthenticationProviderTests.cs index 9e9519c..2c2e63c 100644 --- a/Microsoft.Kiota.Authentication.Azure.Tests/AzureIdentityAuthenticationProviderTests.cs +++ b/Microsoft.Kiota.Authentication.Azure.Tests/AzureIdentityAuthenticationProviderTests.cs @@ -88,6 +88,23 @@ public async Task GetAuthorizationTokenAsyncThrowsExcpetionForNonHTTPsUrl() var exception = await Assert.ThrowsAsync(() => azureIdentityAuthenticationProvider.GetAuthorizationTokenAsync(new Uri(nonHttpsUrl))); Assert.Equal("Only https is supported", exception.Message); } + + [Theory] + [InlineData("http://localhost/test")] + [InlineData("http://localhost:8080/test")] + [InlineData("http://127.0.0.1:8080/test")] + [InlineData("http://127.0.0.1/test")] + public async Task GetAuthorizationTokenAsyncDoesNotThrowsExcpetionForNonHTTPsUrlIfLocalHost(string nonHttpsUrl) + { + // Arrange + var mockTokenCredential = new Mock(); + mockTokenCredential.Setup(credential => credential.GetTokenAsync(It.IsAny(), It.IsAny())).Returns(new ValueTask(new AccessToken(string.Empty, DateTimeOffset.Now))); + var azureIdentityAuthenticationProvider = new AzureIdentityAccessTokenProvider(mockTokenCredential.Object); + + // Assert + var token = await azureIdentityAuthenticationProvider.GetAuthorizationTokenAsync(new Uri(nonHttpsUrl)); + Assert.Empty(token); + } [Fact] public async Task AddsClaimsToTheTokenContext() { diff --git a/src/AzureIdentityAccessTokenProvider.cs b/src/AzureIdentityAccessTokenProvider.cs index 4077d69..f797053 100644 --- a/src/AzureIdentityAccessTokenProvider.cs +++ b/src/AzureIdentityAccessTokenProvider.cs @@ -50,6 +50,14 @@ public AzureIdentityAccessTokenProvider(TokenCredential credential, string []? a private const string ClaimsKey = "claims"; + private readonly HashSet _localHostStrings = new HashSet(StringComparer.OrdinalIgnoreCase) + { + "localhost", + "[::1]", + "::1", + "127.0.0.1" + }; + /// public async Task GetAuthorizationTokenAsync(Uri uri, Dictionary? additionalAuthenticationContext = default, CancellationToken cancellationToken = default) { @@ -59,7 +67,7 @@ public async Task GetAuthorizationTokenAsync(Uri uri, Dictionaryhttps://aka.ms/kiota/docs true true - 1.1.0 + 1.1.1 true true