Skip to content

Commit eaebd77

Browse files
authored
Ignore CachedAuth if Broker is present in AuthMode on win 10 or 11 (#419)
* Ignore cached auth if broker is present on win 10 or 11 * Update changelog
1 parent 72a9469 commit eaebd77

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- Removed ChachedAuth mode if Broker is already present in auth modes on windows 10 or 11 since Broker already tries CachedAuth in a compliant way.
810

911
## [0.9.0] - 2024-11-07
1012
### Removed

src/MSALWrapper.Test/AuthFlow/AuthFlowFactoryTest.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ public void Broker_Only()
101101

102102
IEnumerable<IAuthFlow> subject = this.Subject(AuthMode.Broker);
103103

104-
subject.Should().HaveCount(2);
104+
subject.Should().HaveCount(1);
105105
subject
106106
.Select(a => a.GetType())
107107
.Should()
108-
.ContainInOrder(typeof(CachedAuth), typeof(Broker));
108+
.Contain(typeof(Broker));
109109
}
110110

111111
[Test]
@@ -115,12 +115,11 @@ public void Windows10Or11_Defaults()
115115

116116
IEnumerable<IAuthFlow> subject = this.Subject(AuthMode.Default);
117117

118-
subject.Should().HaveCount(3);
118+
subject.Should().HaveCount(2);
119119
subject
120120
.Select(a => a.GetType())
121121
.Should()
122122
.ContainInOrder(
123-
typeof(CachedAuth),
124123
typeof(Broker),
125124
typeof(Web));
126125
}
@@ -149,12 +148,11 @@ public void Windows10Or11_All()
149148

150149
IEnumerable<IAuthFlow> subject = this.Subject(AuthMode.All);
151150

152-
subject.Should().HaveCount(5);
151+
subject.Should().HaveCount(4);
153152
subject
154153
.Select(a => a.GetType())
155154
.Should()
156155
.ContainInOrder(
157-
typeof(CachedAuth),
158156
typeof(Broker),
159157
typeof(Web),
160158
typeof(DeviceCode));
@@ -228,13 +226,12 @@ public void AllModes_Windows10Or11()
228226
IEnumerable<IAuthFlow> subject = this.Subject(AuthMode.All);
229227

230228
this.pcaWrapperMock.VerifyAll();
231-
subject.Should().HaveCount(5);
229+
subject.Should().HaveCount(4);
232230
subject
233231
.Select(flow => flow.GetType())
234232
.Should()
235233
.BeEquivalentTo(new[]
236234
{
237-
typeof(CachedAuth),
238235
typeof(IntegratedWindowsAuthentication),
239236
typeof(Broker),
240237
typeof(Web),

src/MSALWrapper/AuthFlow/AuthFlowFactory.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ public static IEnumerable<IAuthFlow> Create(
3737

3838
// This is a list. The order in which flows get added is very important
3939
// as it sets the order in which auth flows will be attempted.
40-
List<IAuthFlow> flows = new List<IAuthFlow>
40+
List<IAuthFlow> flows = new List<IAuthFlow>();
41+
42+
// We skip CachedAuth if Broker is present in authMode on windows 10 or 11, since Broker
43+
// already tries CachedAuth with its PCAWrapper object built using withBroker(options).
44+
if (!(authMode.IsBroker() && platformUtils.IsWindows10Or11()))
4145
{
42-
// We always try cached auth first.
43-
new CachedAuth(logger, authParams, preferredDomain, pcaWrapper),
44-
};
46+
flows.Add(new CachedAuth(logger, authParams, preferredDomain, pcaWrapper));
47+
}
4548

4649
// We try IWA as the first auth flow as it works for any Windows version
4750
// and tries to auth silently.

0 commit comments

Comments
 (0)