Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameterless constructor for Microsoft.Artifacts.Authentication.TokenRequest #502

Merged
merged 2 commits into from
Jul 24, 2024
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
2 changes: 1 addition & 1 deletion Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CredentialProviderVersion>1.2.0</CredentialProviderVersion>
<CredentialProviderVersion>1.2.1</CredentialProviderVersion>
<VersionSuffix></VersionSuffix>
<TargetFrameworks>netcoreapp3.1;net461;net6.0</TargetFrameworks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public override async Task<bool> 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);
Expand Down Expand Up @@ -106,7 +106,7 @@ public override async Task<GetAuthenticationCredentialsResponse> HandleRequestAs
IEnumerable<ITokenProvider> tokenProviders = await tokenProvidersFactory.GetAsync(authInfo.EntraAuthorityUri);
cancellationToken.ThrowIfCancellationRequested();

var tokenRequest = new TokenRequest(request.Uri)
var tokenRequest = new TokenRequest()
{
IsRetry = request.IsRetry,
IsNonInteractive = request.IsNonInteractive,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override async Task<GetAuthenticationCredentialsResponse> HandleRequestAs
IEnumerable<ITokenProvider> tokenProviders = await TokenProvidersFactory.GetAsync(authInfo.EntraAuthorityUri);
cancellationToken.ThrowIfCancellationRequested();

var tokenRequest = new TokenRequest(request.Uri)
var tokenRequest = new TokenRequest()
{
IsRetry = request.IsRetry,
IsNonInteractive = true,
Expand Down Expand Up @@ -139,7 +139,7 @@ public override async Task<GetAuthenticationCredentialsResponse> HandleRequestAs
bearerToken,
null,
MessageResponseCode.Success);
}
}
}

Verbose(string.Format(Resources.BuildTaskEndpointNoMatchingUrl, uriString));
Expand Down
12 changes: 6 additions & 6 deletions src/Authentication.Tests/MsalAuthenticationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions src/Authentication.Tests/TokenProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -101,7 +101,7 @@ public void MsalServicePrincipalContractTest()
.Returns(new Mock<IAppConfig>().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);
Expand Down Expand Up @@ -133,7 +133,7 @@ public void MsalManagedIdentityContractTest()
.Returns(new Mock<IAppConfig>().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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>0.2.0</VersionPrefix>
<VersionPrefix>0.2.1</VersionPrefix>
<Authors>Microsoft</Authors>
<Owners>Microsoft</Owners>
<Description>Azure Artifacts authentication library for credential providers.</Description>
Expand Down
6 changes: 4 additions & 2 deletions src/Authentication/TokenRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down