Skip to content

Commit

Permalink
Remove AccountSource from public IAccount interface to avoid breaking…
Browse files Browse the repository at this point in the history
… change (#4848)

* Remove AccountSource from public IAccount interface to avoid breaking change

* Update IAccount.cs

* Fix compilation errors

* Update SilentRequest.cs
  • Loading branch information
ashok672 authored Jul 19, 2024
1 parent 574f2e6 commit d134813
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
6 changes: 0 additions & 6 deletions src/client/Microsoft.Identity.Client/IAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,5 @@ public interface IAccount
/// </summary>
/// <remarks>Can be null, for example if this account was migrated to MSAL.NET from ADAL.NET v3's token cache</remarks>
AccountId HomeAccountId { get; }

/// <summary>
/// The initial flow that established the account. For example, device code flow.
/// </summary>
/// <remarks>Can be null. Currently only device code flow updates this property with a valid string</remarks>
string AccountSource { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ protected override async Task<AuthenticationResult> ExecuteAsync(CancellationTok
UiRequiredExceptionClassification.AcquireTokenSilentFailed);
}

bool isAccountSourceDeviceCodeFlow = !string.IsNullOrEmpty(AuthenticationRequestParameters.Account.AccountSource) &&
AuthenticationRequestParameters.Account.AccountSource == "device_code_flow";
var account = AuthenticationRequestParameters.Account as Account;
bool isAccountSourceDeviceCodeFlow = account !=null &&
account.AccountSource == "device_code_flow";

if (isBrokerConfigured && !isAccountSourceDeviceCodeFlow)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1154,13 +1154,14 @@ async Task<Account> ITokenCacheInternal.GetAccountAssociatedWithAccessTokenAsync

var tenantProfiles = await GetTenantProfilesAsync(requestParameters, msalAccessTokenCacheItem.HomeAccountId).ConfigureAwait(false);

var account = requestParameters.Account as Account;
var accountCacheItem = Accessor.GetAccount(
new MsalAccountCacheItem(
msalAccessTokenCacheItem.Environment,
msalAccessTokenCacheItem.TenantId,
msalAccessTokenCacheItem.HomeAccountId,
requestParameters.Account?.AccountSource,
requestParameters.Account?.Username));
account?.AccountSource,
account?.Username));

return new Account(
msalAccessTokenCacheItem.HomeAccountId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ private async Task AcquireTokenSilentAfterDeviceCodeFlowWithBrokerAsync(LabRespo
Assert.IsFalse(userCacheAccess.LastAfterAccessNotificationArgs.IsApplicationCache);

Assert.IsNotNull(result);
Assert.IsTrue(result.Account.AccountSource == "device_code_flow");
var account = result.Account as Account;
Assert.IsTrue(account.AccountSource == "device_code_flow");
Assert.IsTrue(!string.IsNullOrEmpty(result.AccessToken));
TestCommon.ValidateNoKerberosTicketFromAuthenticationResult(result);

Expand Down
3 changes: 2 additions & 1 deletion tests/devapps/WAM/NetCoreWinFormsWam/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,8 @@ public AccountModel(IAccount account, string displayValue = null)
"" :
$"({Account.Environment})";
string homeTenantId = account?.HomeAccountId?.TenantId?.Substring(0, 5);
string accountSource = account?.AccountSource;
var accountObj = account as Account;
string accountSource = accountObj?.AccountSource;

DisplayValue = displayValue ?? $"{Account.Username} {env} {homeTenantId} {accountSource}";
}
Expand Down

0 comments on commit d134813

Please sign in to comment.