Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ internal static AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder Cr
.WithScopes(scopes);
}

/// <summary>
/// Applicable to first-party applications only, this method also allows to specify
/// if the <see href="https://datatracker.ietf.org/doc/html/rfc7517#section-4.7">x5c claim</see> should be sent to Azure AD.
/// Sending the x5c enables application developers to achieve easy certificate roll-over in Azure AD:
/// this method will send the certificate chain to Azure AD along with the token request,
/// so that Azure AD can use it to validate the subject name based on a trusted issuer policy.
/// This saves the application admin from the need to explicitly manage the certificate rollover
/// (either via portal or PowerShell/CLI operation). For details see https://aka.ms/msal-net-sni
/// </summary>
/// <param name="withSendX5C"><c>true</c> if the x5c should be sent. Otherwise <c>false</c>.
/// The default is <c>false</c></param>
/// <returns>The builder to chain the .With methods</returns>
public AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder WithSendX5C(bool withSendX5C)
{
Parameters.SendX5C = withSendX5C;
return this;
}

/// <inheritdoc/>
internal override Task<AuthenticationResult> ExecuteInternalAsync(CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder.WithSendX5C(bool withSendX5C) -> Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder

Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder.WithSendX5C(bool withSendX5C) -> Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder

Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder.WithSendX5C(bool withSendX5C) -> Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder

Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder.WithSendX5C(bool withSendX5C) -> Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder

Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder.WithSendX5C(bool withSendX5C) -> Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder

Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder.WithSendX5C(bool withSendX5C) -> Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder

Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,43 @@ public async Task RopcCcaSendsX5CAsync(bool sendX5C)
}
}

[DataTestMethod]
[DataRow(true)]
[DataRow(false)]
public async Task RopcCcaSendsX5CUsingRequestLevelAPIAsync(bool sendX5C)
{
using (var harness = CreateTestHarness())
{
var certificate = CertHelper.GetOrCreateTestCert();
var exportedCertificate = Convert.ToBase64String(certificate.Export(X509ContentType.Cert));

var app = ConfidentialClientApplicationBuilder
.Create(TestConstants.ClientId)
.WithHttpManager(harness.HttpManager)
.WithCertificate(certificate)
.Build();

harness.HttpManager.AddInstanceDiscoveryMockHandler();

harness.HttpManager.AddMockHandler(
CreateTokenResponseHttpHandlerWithX5CValidation(
clientCredentialFlow: false,
expectedX5C: sendX5C ? exportedCertificate : null));

var result = await (app as IByUsernameAndPassword)
.AcquireTokenByUsernamePassword(
TestConstants.s_scope,
TestConstants.Username,
TestConstants.DefaultPassword)
.WithSendX5C(sendX5C)
.ExecuteAsync()
.ConfigureAwait(false);

Assert.IsNotNull(result);
Assert.AreEqual(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource);
}
}

[TestMethod]
public async Task EnsureCertificateSerialNumberIsAddedToCacheKeyTestAsync()
{
Expand Down