diff --git a/Build.props b/Build.props index c217338f..660beeb0 100644 --- a/Build.props +++ b/Build.props @@ -1,7 +1,7 @@ - 1.2.0 + 1.2.1 netcoreapp3.1;net461;net6.0 diff --git a/CredentialProvider.Microsoft/CredentialProviders/Vsts/VstsCredentialProvider.cs b/CredentialProvider.Microsoft/CredentialProviders/Vsts/VstsCredentialProvider.cs index 56904823..c7a2400f 100644 --- a/CredentialProvider.Microsoft/CredentialProviders/Vsts/VstsCredentialProvider.cs +++ b/CredentialProvider.Microsoft/CredentialProviders/Vsts/VstsCredentialProvider.cs @@ -46,9 +46,9 @@ public override async Task CanProvideCredentialsAsync(Uri uri) string uriPrefixesStringEnvVar = Environment.GetEnvironmentVariable(EnvUtil.BuildTaskUriPrefixes); string accessTokenEnvVar = Environment.GetEnvironmentVariable(EnvUtil.BuildTaskAccessToken); - if (string.IsNullOrWhiteSpace(feedEndPointsJsonEnvVar) == false || - string.IsNullOrWhiteSpace(externalFeedEndPointsJsonEnvVar) == false || - string.IsNullOrWhiteSpace(uriPrefixesStringEnvVar) == false || + if (string.IsNullOrWhiteSpace(feedEndPointsJsonEnvVar) == false || + string.IsNullOrWhiteSpace(externalFeedEndPointsJsonEnvVar) == false || + string.IsNullOrWhiteSpace(uriPrefixesStringEnvVar) == false || string.IsNullOrWhiteSpace(accessTokenEnvVar) == false) { Verbose(Resources.BuildTaskCredProviderIsUsedError); @@ -106,7 +106,7 @@ public override async Task HandleRequestAs IEnumerable tokenProviders = await tokenProvidersFactory.GetAsync(authInfo.EntraAuthorityUri); cancellationToken.ThrowIfCancellationRequested(); - var tokenRequest = new TokenRequest(request.Uri) + var tokenRequest = new TokenRequest() { IsRetry = request.IsRetry, IsNonInteractive = request.IsNonInteractive, diff --git a/CredentialProvider.Microsoft/CredentialProviders/VstsBuildTaskServiceEndpoint/VstsBuildTaskServiceEndpointCredentialProvider.cs b/CredentialProvider.Microsoft/CredentialProviders/VstsBuildTaskServiceEndpoint/VstsBuildTaskServiceEndpointCredentialProvider.cs index a9c3fc28..fbcf820a 100644 --- a/CredentialProvider.Microsoft/CredentialProviders/VstsBuildTaskServiceEndpoint/VstsBuildTaskServiceEndpointCredentialProvider.cs +++ b/CredentialProvider.Microsoft/CredentialProviders/VstsBuildTaskServiceEndpoint/VstsBuildTaskServiceEndpointCredentialProvider.cs @@ -92,7 +92,7 @@ public override async Task HandleRequestAs IEnumerable tokenProviders = await TokenProvidersFactory.GetAsync(authInfo.EntraAuthorityUri); cancellationToken.ThrowIfCancellationRequested(); - var tokenRequest = new TokenRequest(request.Uri) + var tokenRequest = new TokenRequest() { IsRetry = request.IsRetry, IsNonInteractive = true, @@ -139,7 +139,7 @@ public override async Task HandleRequestAs bearerToken, null, MessageResponseCode.Success); - } + } } Verbose(string.Format(Resources.BuildTaskEndpointNoMatchingUrl, uriString)); diff --git a/src/Authentication.Tests/MsalAuthenticationTests.cs b/src/Authentication.Tests/MsalAuthenticationTests.cs index b7e89e6d..f6a42ddc 100644 --- a/src/Authentication.Tests/MsalAuthenticationTests.cs +++ b/src/Authentication.Tests/MsalAuthenticationTests.cs @@ -35,7 +35,7 @@ public class MsalAuthenticationTests public async Task MsalAcquireTokenSilentTest() { var tokenProvider = new MsalSilentTokenProvider(app, logger); - var tokenRequest = new TokenRequest(PackageUri); + var tokenRequest = new TokenRequest(); var result = await tokenProvider.GetTokenAsync(tokenRequest); @@ -47,7 +47,7 @@ public async Task MsalAcquireTokenSilentTest() public async Task MsalAcquireTokenByIntegratedWindowsAuthTest() { var tokenProvider = new MsalIntegratedWindowsAuthTokenProvider(app, logger); - var tokenRequest = new TokenRequest(PackageUri); + var tokenRequest = new TokenRequest(); var result = await tokenProvider.GetTokenAsync(tokenRequest); @@ -59,7 +59,7 @@ public async Task MsalAcquireTokenByIntegratedWindowsAuthTest() public async Task MsalAcquireTokenInteractiveTest() { var tokenProvider = new MsalInteractiveTokenProvider(app, logger); - var tokenRequest = new TokenRequest(PackageUri); + var tokenRequest = new TokenRequest(); var result = await tokenProvider.GetTokenAsync(tokenRequest); @@ -71,7 +71,7 @@ public async Task MsalAcquireTokenInteractiveTest() public async Task MsalAcquireTokenWithDeviceCodeTest() { var tokenProvider = new MsalDeviceCodeTokenProvider(app, logger); - var tokenRequest = new TokenRequest(PackageUri); + var tokenRequest = new TokenRequest(); var result = await tokenProvider.GetTokenAsync(tokenRequest); @@ -83,7 +83,7 @@ public async Task MsalAcquireTokenWithDeviceCodeTest() public async Task MsalAquireTokenWithManagedIdentity() { var tokenProvider = new MsalManagedIdentityTokenProvider(app, logger); - var tokenRequest = new TokenRequest(PackageUri); + var tokenRequest = new TokenRequest(); tokenRequest.ClientId = Environment.GetEnvironmentVariable("ARTIFACTS_CREDENTIALPROVIDER_TEST_CLIENTID"); var result = await tokenProvider.GetTokenAsync(tokenRequest); @@ -96,7 +96,7 @@ public async Task MsalAquireTokenWithManagedIdentity() public async Task MsalAquireTokenWithServicePrincipal() { var tokenProvider = new MsalServicePrincipalTokenProvider(app, logger); - var tokenRequest = new TokenRequest(PackageUri); + var tokenRequest = new TokenRequest(); tokenRequest.ClientId = Environment.GetEnvironmentVariable("ARTIFACTS_CREDENTIALPROVIDER_TEST_CLIENTID"); tokenRequest.ClientCertificate = new X509Certificate2(Environment.GetEnvironmentVariable("ARTIFACTS_CREDENTIALPROVIDER_TEST_CERT_PATH") ?? string.Empty); diff --git a/src/Authentication.Tests/TokenProviderTests.cs b/src/Authentication.Tests/TokenProviderTests.cs index e971fa2e..6c9322db 100644 --- a/src/Authentication.Tests/TokenProviderTests.cs +++ b/src/Authentication.Tests/TokenProviderTests.cs @@ -16,7 +16,7 @@ public class TokenProviderTests public void MsalSilentContractTest() { var tokenProvider = new MsalSilentTokenProvider(appMock.Object, loggerMock.Object); - var tokenRequest = new TokenRequest(PackageUri); + var tokenRequest = new TokenRequest(); Assert.IsNotNull(tokenProvider.Name); Assert.IsFalse(tokenProvider.IsInteractive); @@ -30,7 +30,7 @@ public void MsalSilentContractTest() public void MsalIntegratedWindowsAuthContractTest() { var tokenProvider = new MsalIntegratedWindowsAuthTokenProvider(appMock.Object, loggerMock.Object); - var tokenRequest = new TokenRequest(PackageUri); + var tokenRequest = new TokenRequest(); var windowsIntegratedAuthSupported = Environment.OSVersion.Platform == PlatformID.Win32NT; Assert.IsNotNull(tokenProvider.Name); @@ -47,7 +47,7 @@ public void MsalIntegratedWindowsAuthContractTest() public void MsalInteractiveContractTest() { var tokenProvider = new MsalInteractiveTokenProvider(appMock.Object, loggerMock.Object); - var tokenRequest = new TokenRequest(PackageUri); + var tokenRequest = new TokenRequest(); Assert.IsNotNull(tokenProvider.Name); Assert.IsTrue(tokenProvider.IsInteractive); @@ -82,7 +82,7 @@ public void MsalInteractiveContractTest() public void MsalDeviceCodeFlowContractTest() { var tokenProvider = new MsalDeviceCodeTokenProvider(appMock.Object, loggerMock.Object); - var tokenRequest = new TokenRequest(PackageUri); + var tokenRequest = new TokenRequest(); Assert.IsNotNull(tokenProvider.Name); Assert.IsTrue(tokenProvider.IsInteractive); @@ -101,7 +101,7 @@ public void MsalServicePrincipalContractTest() .Returns(new Mock().Object); var tokenProvider = new MsalServicePrincipalTokenProvider(appMock.Object, loggerMock.Object); - var tokenRequest = new TokenRequest(PackageUri); + var tokenRequest = new TokenRequest(); Assert.IsNotNull(tokenProvider.Name); Assert.IsFalse(tokenProvider.IsInteractive); @@ -133,7 +133,7 @@ public void MsalManagedIdentityContractTest() .Returns(new Mock().Object); var tokenProvider = new MsalManagedIdentityTokenProvider(appMock.Object, loggerMock.Object); - var tokenRequest = new TokenRequest(PackageUri); + var tokenRequest = new TokenRequest(); Assert.IsNotNull(tokenProvider.Name); Assert.IsFalse(tokenProvider.IsInteractive); diff --git a/src/Authentication/Microsoft.Artifacts.Authentication.csproj b/src/Authentication/Microsoft.Artifacts.Authentication.csproj index c756554a..ff0fe4c1 100644 --- a/src/Authentication/Microsoft.Artifacts.Authentication.csproj +++ b/src/Authentication/Microsoft.Artifacts.Authentication.csproj @@ -7,7 +7,7 @@ latest enable enable - 0.2.0 + 0.2.1 Microsoft Microsoft Azure Artifacts authentication library for credential providers. diff --git a/src/Authentication/TokenRequest.cs b/src/Authentication/TokenRequest.cs index e5bd873c..c59093be 100644 --- a/src/Authentication/TokenRequest.cs +++ b/src/Authentication/TokenRequest.cs @@ -9,12 +9,14 @@ namespace Microsoft.Artifacts.Authentication; public class TokenRequest { + [Obsolete($"The uri parameter is unused and unnecessary. Use the parameterless constructor instead.")] public TokenRequest(Uri uri) { - this.Uri = uri ?? throw new ArgumentNullException(nameof(uri)); } - public Uri Uri { get; } + public TokenRequest() + { + } public bool IsRetry { get; set; }