From 6c59182ff034f5170d377ba87f0cd1c4b27b3350 Mon Sep 17 00:00:00 2001 From: Haard Shah Date: Thu, 5 Dec 2024 13:35:44 -0500 Subject: [PATCH 1/2] Ignore cached auth if broker is present on win 10 or 11 --- .../AuthFlow/AuthFlowFactoryTest.cs | 13 +++++-------- src/MSALWrapper/AuthFlow/AuthFlowFactory.cs | 11 +++++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/MSALWrapper.Test/AuthFlow/AuthFlowFactoryTest.cs b/src/MSALWrapper.Test/AuthFlow/AuthFlowFactoryTest.cs index c025602a..2c7336ac 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 9fffc5f4..24b24103 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. From 95b88f8531d73976e7afe2bd7ced52abd9a9c23f Mon Sep 17 00:00:00 2001 From: Haard Shah Date: Thu, 5 Dec 2024 14:11:17 -0500 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b15725ec..a224bd33 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