Skip to content

Commit 3d33ee3

Browse files
bgavrilMSjennyf19
andauthored
Change GetSignedAssertion public API (#2854)
* Change GetSignedAssertion public API * update * PR comments * Add Async suffix --------- Co-authored-by: jennyf19 <jeferrie@microsoft.com>
1 parent d2560ee commit 3d33ee3

File tree

8 files changed

+25
-20
lines changed

8 files changed

+25
-20
lines changed

src/Microsoft.Identity.Web.Certificate/SignedAssertionFilePathCredentialsLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public async Task LoadIfNeededAsync(CredentialDescription credentialDescription,
3636
{
3737
// Given that managed identity can be not available locally, we need to try to get a
3838
// signed assertion, and if it fails, move to the next credentials
39-
_= await signedAssertion!.GetSignedAssertion(CancellationToken.None);
39+
_= await signedAssertion!.GetSignedAssertionAsync(null);
4040
credentialDescription.CachedValue = signedAssertion;
4141
}
4242
catch (Exception)

src/Microsoft.Identity.Web.Certificate/SignedAssertionFromManagedIdentityCredentialLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public async Task LoadIfNeededAsync(CredentialDescription credentialDescription,
2525
{
2626
// Given that managed identity can be not available locally, we need to try to get a
2727
// signed assertion, and if it fails, move to the next credentials
28-
_= await managedIdentityClientAssertion!.GetSignedAssertion(CancellationToken.None);
28+
_= await managedIdentityClientAssertion!.GetSignedAssertionAsync(null);
2929
credentialDescription.CachedValue = managedIdentityClientAssertion;
3030
}
3131
catch (AuthenticationFailedException)

src/Microsoft.Identity.Web.Certificateless/AzureIdentityForKubernetesClientAssertion.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88
using Microsoft.Extensions.Logging;
9+
using Microsoft.Identity.Client;
910
using Microsoft.IdentityModel.JsonWebTokens;
1011

1112
namespace Microsoft.Identity.Web
@@ -65,7 +66,7 @@ public AzureIdentityForKubernetesClientAssertion(string? filePath, ILogger? logg
6566
/// Get the signed assertion from a file.
6667
/// </summary>
6768
/// <returns>The signed assertion.</returns>
68-
protected override Task<ClientAssertion> GetClientAssertion(CancellationToken cancellationToken)
69+
protected override Task<ClientAssertion> GetClientAssertionAsync(AssertionRequestOptions? assertionRequestOptions)
6970
{
7071
if (_filePath != null && !File.Exists(_filePath))
7172
{

src/Microsoft.Identity.Web.Certificateless/ClientAssertionProviderBase.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Threading;
66
using System.Threading.Tasks;
7+
using Microsoft.Identity.Client;
78

89
namespace Microsoft.Identity.Web
910
{
@@ -16,9 +17,9 @@ public abstract class ClientAssertionProviderBase
1617
/// <summary>
1718
/// Gets the Client assertion
1819
/// </summary>
19-
/// <param name="cancellationToken"></param>
20+
/// <param name="assertionRequestOptions"></param>
2021
/// <returns></returns>
21-
protected abstract Task<ClientAssertion> GetClientAssertion(CancellationToken cancellationToken);
22+
protected abstract Task<ClientAssertion> GetClientAssertionAsync(AssertionRequestOptions? assertionRequestOptions);
2223

2324
/// <summary>
2425
/// Client assertion.
@@ -28,13 +29,13 @@ public abstract class ClientAssertionProviderBase
2829
/// <summary>
2930
/// Get the signed assertion (and refreshes it if needed).
3031
/// </summary>
31-
/// <param name="cancellationToken">Cancellation token.</param>
32+
/// <param name="assertionRequestOptions">Input object which is populated by the SDK.</param>
3233
/// <returns>The signed assertion.</returns>
33-
public async Task<string> GetSignedAssertion(CancellationToken cancellationToken)
34+
public async Task<string> GetSignedAssertionAsync(AssertionRequestOptions? assertionRequestOptions)
3435
{
3536
if (_clientAssertion == null || (Expiry != null && DateTimeOffset.Now > Expiry))
3637
{
37-
_clientAssertion = await GetClientAssertion(cancellationToken).ConfigureAwait(false);
38+
_clientAssertion = await GetClientAssertionAsync(assertionRequestOptions).ConfigureAwait(false);
3839
}
3940

4041
return _clientAssertion.SignedAssertion;

src/Microsoft.Identity.Web.Certificateless/ManagedIdentityClientAssertion.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Azure.Core;
77
using Azure.Identity;
8+
using Microsoft.Identity.Client;
89
using Microsoft.Identity.Web.Certificateless;
910

1011
namespace Microsoft.Identity.Web
@@ -54,11 +55,11 @@ public ManagedIdentityClientAssertion(string? managedIdentityClientId, string? t
5455
/// acquired with managed identity (certificateless).
5556
/// </summary>
5657
/// <returns>The signed assertion.</returns>
57-
protected override async Task<ClientAssertion> GetClientAssertion(CancellationToken cancellationToken)
58+
protected override async Task<ClientAssertion> GetClientAssertionAsync(AssertionRequestOptions? assertionRequestOptions)
5859
{
5960
var result = await _credential.GetTokenAsync(
6061
new TokenRequestContext([_tokenExchangeUrl], null),
61-
cancellationToken).ConfigureAwait(false);
62+
assertionRequestOptions?.CancellationToken ?? default).ConfigureAwait(false);
6263
return new ClientAssertion(result.Token, result.ExpiresOn);
6364
}
6465
}

src/Microsoft.Identity.Web.TokenAcquisition/ConfidentialClientApplicationBuilderExtension.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,23 @@ public static async Task<ConfidentialClientApplicationBuilder> WithClientCredent
5858
else
5959
{
6060
Logger.UsingManagedIdentity(logger);
61-
return builder.WithClientAssertion((credential.CachedValue as ManagedIdentityClientAssertion)!.GetSignedAssertion);
61+
return builder.WithClientAssertion((credential.CachedValue as ManagedIdentityClientAssertion)!.GetSignedAssertionAsync);
6262
}
6363
}
6464
if (credential.SourceType == CredentialSource.SignedAssertionFilePath)
6565
{
6666
if (!credential.Skip)
6767
{
6868
Logger.UsingPodIdentityFile(logger, credential.SignedAssertionFileDiskPath ?? "not found");
69-
return builder.WithClientAssertion((credential.CachedValue as AzureIdentityForKubernetesClientAssertion)!.GetSignedAssertion);
69+
return builder.WithClientAssertion((credential.CachedValue as AzureIdentityForKubernetesClientAssertion)!.GetSignedAssertionAsync);
7070
}
7171
}
7272
if (credential.SourceType == CredentialSource.SignedAssertionFromVault)
7373
{
7474
if (!credential.Skip)
7575
{
7676
Logger.UsingSignedAssertionFromVault(logger, credential.KeyVaultUrl ?? "undefined");
77-
return builder.WithClientAssertion((credential.CachedValue as ClientAssertionProviderBase)!.GetSignedAssertion);
77+
return builder.WithClientAssertion((credential.CachedValue as ClientAssertionProviderBase)!.GetSignedAssertionAsync);
7878
}
7979
}
8080
}

tests/Microsoft.Identity.Web.Test/AzureIdentityForKubernetesClientAssertionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public async Task GetAksClientAssertion_WhenSpecifiedSignedAssertionFileExists_R
3030
AzureIdentityForKubernetesClientAssertion azureIdentityForKubernetesClientAssertion = new AzureIdentityForKubernetesClientAssertion(_filePath);
3131

3232
// Act
33-
string signedAssertion = await azureIdentityForKubernetesClientAssertion.GetSignedAssertion(CancellationToken.None);
33+
string signedAssertion = await azureIdentityForKubernetesClientAssertion.GetSignedAssertionAsync(null);
3434

3535
// Assert
3636
Assert.NotNull(signedAssertion);
@@ -45,7 +45,7 @@ public async Task GetAksClientAssertion_WhenEnvironmentVariablePointsToSignedAss
4545
AzureIdentityForKubernetesClientAssertion azureIdentityForKubernetesClientAssertion = new AzureIdentityForKubernetesClientAssertion();
4646

4747
// Act
48-
string signedAssertion = await azureIdentityForKubernetesClientAssertion.GetSignedAssertion(CancellationToken.None);
48+
string signedAssertion = await azureIdentityForKubernetesClientAssertion.GetSignedAssertionAsync(null);
4949

5050
// Assert
5151
Assert.NotNull(signedAssertion);
@@ -62,7 +62,7 @@ public async Task GetAksClientAssertion_WhenSignedAssertionFileDoesNotExist_Thro
6262
AzureIdentityForKubernetesClientAssertion azureIdentityForKubernetesClientAssertion = new AzureIdentityForKubernetesClientAssertion(filePath);
6363

6464
// Act & Assert
65-
var ex = await Assert.ThrowsAsync<FileNotFoundException>(() => azureIdentityForKubernetesClientAssertion.GetSignedAssertion(CancellationToken.None));
65+
var ex = await Assert.ThrowsAsync<FileNotFoundException>(() => azureIdentityForKubernetesClientAssertion.GetSignedAssertionAsync(null));
6666
Assert.Contains(filePath, ex.Message, System.StringComparison.OrdinalIgnoreCase);
6767
}
6868
}

tests/Microsoft.Identity.Web.Test/ClientAssertionTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Globalization;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.Identity.Client;
89
using Xunit;
910

1011
namespace Microsoft.Identity.Web.Test
@@ -13,7 +14,7 @@ public class TestClientAssertion : ClientAssertionProviderBase
1314
{
1415
private int _n = 0;
1516

16-
protected override Task<ClientAssertion> GetClientAssertion(CancellationToken cancellationToken)
17+
protected override Task<ClientAssertion> GetClientAssertionAsync(AssertionRequestOptions? assertionRequestOptions)
1718
{
1819
_n++;
1920
return Task.FromResult(new ClientAssertion(
@@ -28,16 +29,17 @@ public class ClientAssertionTests
2829
public async Task TestClientAssertion()
2930
{
3031
TestClientAssertion clientAssertionDescription = new TestClientAssertion();
32+
AssertionRequestOptions options = new AssertionRequestOptions();
3133

32-
string assertion = await clientAssertionDescription.GetSignedAssertion(CancellationToken.None).ConfigureAwait(false);
34+
string assertion = await clientAssertionDescription.GetSignedAssertionAsync(options).ConfigureAwait(false);
3335

3436
Assert.Equal("1", assertion);
35-
assertion = await clientAssertionDescription.GetSignedAssertion(CancellationToken.None).ConfigureAwait(false);
37+
assertion = await clientAssertionDescription.GetSignedAssertionAsync(options).ConfigureAwait(false);
3638
Assert.Equal("1", assertion);
3739

3840
Assert.NotNull(clientAssertionDescription.Expiry);
3941
await Task.Delay(clientAssertionDescription.Expiry.Value - DateTimeOffset.Now + TimeSpan.FromMilliseconds(100)).ConfigureAwait(false);
40-
assertion = await clientAssertionDescription.GetSignedAssertion(CancellationToken.None).ConfigureAwait(false);
42+
assertion = await clientAssertionDescription.GetSignedAssertionAsync(options).ConfigureAwait(false);
4143
Assert.Equal("2", assertion);
4244
}
4345

0 commit comments

Comments
 (0)