Skip to content

Commit

Permalink
Ignore cached auth if broker is present on win 10 or 11
Browse files Browse the repository at this point in the history
  • Loading branch information
Haard30 committed Dec 5, 2024
1 parent 72a9469 commit 6c59182
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
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

0 comments on commit 6c59182

Please sign in to comment.