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 @@ -335,8 +335,9 @@ public async Task<AuthenticationResult> GetAuthenticationResultForUserAsync(
{
string username = user.FindFirst(ClaimConstants.Username)?.Value ?? string.Empty;
string password = user.FindFirst(ClaimConstants.Password)?.Value ?? string.Empty;
bool forceRefresh = tokenAcquisitionOptions?.ForceRefresh ?? false;

if (user.GetMsalAccountId() != null)
if (!forceRefresh && user.GetMsalAccountId() != null)
{
try
{
Expand Down Expand Up @@ -372,6 +373,29 @@ public async Task<AuthenticationResult> GetAuthenticationResultForUserAsync(
addInOptions.InvokeOnBeforeTokenAcquisitionForTestUser(builder, tokenAcquisitionOptions, user);
}

// Pass the token acquisition options to the builder
if (tokenAcquisitionOptions != null)
{
var dict = MergeExtraQueryParameters(mergedOptions, tokenAcquisitionOptions);
if (dict != null)
{
builder.WithExtraQueryParameters(dict);
}
if (tokenAcquisitionOptions.ExtraHeadersParameters != null)
{
builder.WithExtraHttpHeaders(tokenAcquisitionOptions.ExtraHeadersParameters);
}
if (tokenAcquisitionOptions.CorrelationId != null)
{
builder.WithCorrelationId(tokenAcquisitionOptions.CorrelationId.Value);
}
builder.WithClaims(tokenAcquisitionOptions.Claims);
if (tokenAcquisitionOptions.PoPConfiguration != null)
{
builder.WithSignedHttpRequestProofOfPossession(tokenAcquisitionOptions.PoPConfiguration);
}
}

var authenticationResult = await builder.ExecuteAsync()
.ConfigureAwait(false);

Expand Down
31 changes: 31 additions & 0 deletions tests/E2E Tests/TokenAcquirerTests/TokenAcquirer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,37 @@ public async Task AcquireToken_ROPC_CCAasync()
Assert.Equal(result.AccessToken, result2.AccessToken);
}

[Fact]
public async Task AcquireToken_ROPC_CCA_WithForceRefresh_async()
{
var tokenAcquirerFactory = TokenAcquirerFactory.GetDefaultInstance();
_ = tokenAcquirerFactory.Build();

var labResponse = await LabUserHelper.GetDefaultUserAsync();

ITokenAcquirer tokenAcquirer = tokenAcquirerFactory.GetTokenAcquirer(
authority: "https://login.microsoftonline.com/organizations",
clientId: "9a192b78-6580-4f8a-aace-f36ffea4f7be",
clientCredentials: s_clientCredentials);

var user = ClaimsPrincipalFactory.FromUsernamePassword(labResponse.User.Upn, labResponse.User.GetOrFetchPassword());

var result = await tokenAcquirer.GetTokenForUserAsync(
scopes: new[] { "https://graph.microsoft.com/.default" }, user: user);

Assert.NotNull(result);
Assert.NotNull(result.AccessToken);

AcquireTokenOptions options = new AcquireTokenOptions { ForceRefresh = true };

var result2 = await tokenAcquirer.GetTokenForUserAsync(tokenAcquisitionOptions: options,
scopes: new[] { "https://graph.microsoft.com/.default" }, user: user);

Assert.NotNull(result2);
Assert.NotNull(result2.AccessToken);
Assert.NotEqual(result.AccessToken, result2.AccessToken);
}

[Fact]
public void AcquireToken_SafeFromMultipleThreads()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public async Task InvokeOnBeforeTokenAcquisitionForUsernamePassword_InvokesEvent
// Arrange
var options = new TokenAcquisitionExtensionOptions();
var acquireTokenOptions = new AcquireTokenOptions();
acquireTokenOptions.ForceRefresh = true;

//Configure mocks
using MockHttpClientFactory mockHttpClient = new();
Expand Down
Loading