Skip to content

Commit 5ea13d3

Browse files
msJinLeiisra-fel
andauthored
Disable WAM When UseDeviceAuthentication is true or paramterset is UserWithCredential (#25404)
* Disable WAM when UseDeviceAuthentication is true or paramterset is UserWithCredential * Address review comments * Address review comments * Update src/Accounts/Accounts/ChangeLog.md Co-authored-by: Yeming Liu <[email protected]> --------- Co-authored-by: Yeming Liu <[email protected]>
1 parent 80e8c80 commit 5ea13d3

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ public override void ExecuteCmdlet()
330330
Guid subscriptionIdGuid;
331331
string subscriptionName = null;
332332
string subscriptionId = null;
333+
334+
//Disable WAM before the issue https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/4786 is fixed
335+
if (ParameterSetName.Equals(UserParameterSet) && UseDeviceAuthentication == true || ParameterSetName.Equals(UserWithCredentialParameterSet))
336+
{
337+
AzConfigReader.Instance?.UpdateConfig(ConfigKeys.EnableLoginByWam, false, ConfigScope.CurrentUser);
338+
}
339+
333340
if (MyInvocation.BoundParameters.ContainsKey(nameof(Subscription)))
334341
{
335342
if (Guid.TryParse(Subscription, out subscriptionIdGuid))

src/Accounts/Accounts/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Disable WAM when the customers login with device code flow or username password (ROPC) flow to prevent a potential issue with token cache.
2223
* Fixed [CVE-2024-35255](https://github.com/advisories/GHSA-m5vv-6r4h-3vj9)
2324
* Updated `Microsoft.Identity.Client.NativeInterop` to fix the WAM pop window issue in elevated mode [#24967]
2425
* Updated the reference of Azure PowerShell Common to 1.3.98-preview.

src/Accounts/Authentication/Utilities/AzConfigReader.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,39 @@ private static IAzureSession Session
3131
}
3232
}
3333

34+
private static IConfigManager instance = null;
35+
36+
public static IConfigManager Instance
37+
{
38+
get
39+
{
40+
if (instance == null)
41+
{
42+
if (!Session.TryGetComponent<IConfigManager>(nameof(IConfigManager), out instance))
43+
{
44+
instance = null;
45+
}
46+
}
47+
return instance;
48+
}
49+
}
50+
3451
public static T GetAzConfig<T>(string key, T defaultValue = default(T))
3552
{
36-
return Session.TryGetComponent<IConfigManager>(nameof(IConfigManager), out IConfigManager configManager) ? configManager.GetConfigValue<T>(key) : defaultValue;
53+
return Instance != null ? Instance.GetConfigValue<T>(key) : defaultValue;
3754
}
3855

3956
static public bool IsWamEnabled(string authority)
4057
{
41-
if (!string.IsNullOrEmpty(authority) && Session.TryGetComponent<IConfigManager>(nameof(IConfigManager), out var config))
58+
if (!string.IsNullOrEmpty(authority) && Instance != null)
4259
{
4360
try
4461
{
4562
if (!authority.EndsWith("/"))
4663
{
4764
authority = authority + "/";
4865
}
49-
return config.GetConfigValue<bool>(ConfigKeys.EnableLoginByWam) && 0 == string.Compare(authority, AzureAuthorityHosts.AzurePublicCloud.OriginalString, System.StringComparison.OrdinalIgnoreCase);
66+
return Instance.GetConfigValue<bool>(ConfigKeys.EnableLoginByWam) && 0 == string.Compare(authority, AzureAuthorityHosts.AzurePublicCloud.OriginalString, System.StringComparison.OrdinalIgnoreCase);
5067
}
5168
catch
5269
{

0 commit comments

Comments
 (0)