Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore CachedAuth if Broker is present in AuthMode on win 10 or 11 #419

Merged
merged 2 commits into from
Dec 9, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- 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.

## [0.9.0] - 2024-11-07
### Removed
Expand Down
13 changes: 5 additions & 8 deletions src/MSALWrapper.Test/AuthFlow/AuthFlowFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public void Broker_Only()

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

subject.Should().HaveCount(2);
subject.Should().HaveCount(1);
subject
.Select(a => a.GetType())
.Should()
.ContainInOrder(typeof(CachedAuth), typeof(Broker));
.Contain(typeof(Broker));
}

[Test]
Expand All @@ -115,12 +115,11 @@ public void Windows10Or11_Defaults()

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

subject.Should().HaveCount(3);
subject.Should().HaveCount(2);
subject
.Select(a => a.GetType())
.Should()
.ContainInOrder(
typeof(CachedAuth),
typeof(Broker),
typeof(Web));
}
Expand Down Expand Up @@ -149,12 +148,11 @@ public void Windows10Or11_All()

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

subject.Should().HaveCount(5);
subject.Should().HaveCount(4);
subject
.Select(a => a.GetType())
.Should()
.ContainInOrder(
typeof(CachedAuth),
typeof(Broker),
typeof(Web),
typeof(DeviceCode));
Expand Down Expand Up @@ -228,13 +226,12 @@ public void AllModes_Windows10Or11()
IEnumerable<IAuthFlow> subject = this.Subject(AuthMode.All);

this.pcaWrapperMock.VerifyAll();
subject.Should().HaveCount(5);
subject.Should().HaveCount(4);
subject
.Select(flow => flow.GetType())
.Should()
.BeEquivalentTo(new[]
{
typeof(CachedAuth),
typeof(IntegratedWindowsAuthentication),
typeof(Broker),
typeof(Web),
Expand Down
11 changes: 7 additions & 4 deletions src/MSALWrapper/AuthFlow/AuthFlowFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ public static IEnumerable<IAuthFlow> Create(

// This is a list. The order in which flows get added is very important
// as it sets the order in which auth flows will be attempted.
List<IAuthFlow> flows = new List<IAuthFlow>
List<IAuthFlow> flows = new List<IAuthFlow>();

// We skip CachedAuth if Broker is present in authMode on windows 10 or 11, since Broker
// already tries CachedAuth with its PCAWrapper object built using withBroker(options).
if (!(authMode.IsBroker() && platformUtils.IsWindows10Or11()))
{
// We always try cached auth first.
new CachedAuth(logger, authParams, preferredDomain, pcaWrapper),
};
flows.Add(new CachedAuth(logger, authParams, preferredDomain, pcaWrapper));
}

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