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

Fixing IWA VPN messaging conditions #407

Merged
merged 3 commits into from
Sep 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ public async Task GetTokenIWA_MsalUIRequired_2FA()
authFlowResult.AuthFlowName.Should().Be("iwa");
}

[Test]
public async Task GetTokenIWA_WSTrustEndpointError()
{
this.SetupIWAWSTrustException();

// Act
AuthFlow.IntegratedWindowsAuthentication iwa = this.Subject();
var authFlowResult = await iwa.GetTokenAsync();

// Assert
authFlowResult.TokenResult.Should().Be(null);
authFlowResult.Errors.Should().HaveCount(1);
authFlowResult.Errors[0].Should().BeOfType(typeof(MsalClientException));
authFlowResult.Errors[0].As<MsalClientException>().ErrorCode.Should().Be("parsing_wstrust_response_failed");
authFlowResult.AuthFlowName.Should().Be("iwa");
}

[Test]
public async Task GetTokenIWA_MsalServiceException()
{
Expand Down Expand Up @@ -136,6 +153,13 @@ private void SetupIWAUIRequiredFor2FA()
.Throws(new MsalUiRequiredException("1", "AADSTS50076 MSAL UI Required Exception!"));
}

private void SetupIWAWSTrustException()
{
this.mockPca
.Setup((pca) => pca.GetTokenIntegratedWindowsAuthenticationAsync(Scopes, It.IsAny<CancellationToken>()))
.Throws(new MsalClientException("parsing_wstrust_response_failed", "WS-Trust endpoint not found"));
}

private void IWAServiceException()
{
this.mockPca
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected override async Task<TokenResult> GetTokenInnerAsync()
this.logger.LogDebug("IWA failed, 2FA is required.");
throw;
}
catch (MsalClientException ex) when (ex.Message.Contains("WS-Trust endpoint not found"))
catch (MsalClientException ex) when (ex.Message.Contains("WS-Trust endpoint not found") || ex.ErrorCode == "parsing_wstrust_response_failed")
{
this.logger.LogDebug($"IWA only works on corporate AD backed network, AzureAuth is trying to use other auth flows if applicable.");
this.logger.LogDebug($"Turn on VPN for IWA mode to succeed.");
Expand Down
Loading