diff --git a/CHANGELOG.md b/CHANGELOG.md index b15725e..a224bd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/MSALWrapper.Test/AuthFlow/AuthFlowFactoryTest.cs b/src/MSALWrapper.Test/AuthFlow/AuthFlowFactoryTest.cs index c025602..2c7336a 100644 --- a/src/MSALWrapper.Test/AuthFlow/AuthFlowFactoryTest.cs +++ b/src/MSALWrapper.Test/AuthFlow/AuthFlowFactoryTest.cs @@ -101,11 +101,11 @@ public void Broker_Only() IEnumerable 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] @@ -115,12 +115,11 @@ public void Windows10Or11_Defaults() IEnumerable 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)); } @@ -149,12 +148,11 @@ public void Windows10Or11_All() IEnumerable 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)); @@ -228,13 +226,12 @@ public void AllModes_Windows10Or11() IEnumerable 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), diff --git a/src/MSALWrapper/AuthFlow/AuthFlowFactory.cs b/src/MSALWrapper/AuthFlow/AuthFlowFactory.cs index 9fffc5f..24b2410 100644 --- a/src/MSALWrapper/AuthFlow/AuthFlowFactory.cs +++ b/src/MSALWrapper/AuthFlow/AuthFlowFactory.cs @@ -37,11 +37,14 @@ public static IEnumerable 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 flows = new List + List flows = new List(); + + // 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.