From 0acca4c9430dd7b2f03eab47eca3cebb2277d807 Mon Sep 17 00:00:00 2001 From: trwalke Date: Tue, 5 Dec 2023 23:40:42 -0800 Subject: [PATCH 1/8] Adding exception help --- .../Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs b/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs index c6e3478e9a..ab73e1c573 100644 --- a/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs +++ b/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs @@ -119,6 +119,8 @@ internal static string GetPiiScrubbedExceptionDetails(Exception ex) sb.AppendLine("=== End of inner exception stack trace ==="); } + sb.AppendLine("To see full exception details, enable Pii Logging."); + if (ex.StackTrace != null) { sb.Append(Environment.NewLine + ex.StackTrace); From 1ac4226dc5c54a09b290f010d424b1f80d3a96f9 Mon Sep 17 00:00:00 2001 From: trwalke Date: Mon, 8 Jan 2024 22:52:30 -0800 Subject: [PATCH 2/8] Updating error message with error code --- .../Internal/Logger/LoggerHelper.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs b/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs index ab73e1c573..b15177005b 100644 --- a/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs +++ b/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs @@ -4,10 +4,13 @@ using System; using System.Globalization; using System.IO; +using System.Linq; using System.Runtime.CompilerServices; using System.Text; using Microsoft.Identity.Client.Core; +using Microsoft.Identity.Client.OAuth2; using Microsoft.Identity.Client.PlatformsCommon.Factories; +using Microsoft.Identity.Client.Utils; using Microsoft.IdentityModel.Abstractions; namespace Microsoft.Identity.Client.Internal.Logger @@ -110,6 +113,8 @@ internal static string GetPiiScrubbedExceptionDetails(Exception ex) { sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "HTTP StatusCode {0}", msalServiceException.StatusCode)); sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "CorrelationId {0}", msalServiceException.CorrelationId)); + var aadError = JsonHelper.GetExistingOrEmptyString(JsonHelper.ParseIntoJsonObject(msalServiceException.ResponseBody), OAuth2ResponseBaseClaim.ErrorDescription).Split(':').FirstOrDefault(); + sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "AAD Error Code {0}", aadError)); } if (ex.InnerException != null) @@ -119,7 +124,7 @@ internal static string GetPiiScrubbedExceptionDetails(Exception ex) sb.AppendLine("=== End of inner exception stack trace ==="); } - sb.AppendLine("To see full exception details, enable Pii Logging."); + sb.AppendLine("To see full exception details, enable Pii Logging. See https://aka.ms/msal-net-logging"); if (ex.StackTrace != null) { From 33d31acffd9b908145637b1e34148ec9b397aaa4 Mon Sep 17 00:00:00 2001 From: trwalke Date: Fri, 12 Jan 2024 02:25:35 -0800 Subject: [PATCH 3/8] Error code update --- .../Internal/Logger/LoggerHelper.cs | 5 ++--- .../HeadlessTests/ClientCredentialsTests.cs | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs b/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs index b15177005b..e658183dc2 100644 --- a/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs +++ b/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs @@ -113,8 +113,7 @@ internal static string GetPiiScrubbedExceptionDetails(Exception ex) { sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "HTTP StatusCode {0}", msalServiceException.StatusCode)); sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "CorrelationId {0}", msalServiceException.CorrelationId)); - var aadError = JsonHelper.GetExistingOrEmptyString(JsonHelper.ParseIntoJsonObject(msalServiceException.ResponseBody), OAuth2ResponseBaseClaim.ErrorDescription).Split(':').FirstOrDefault(); - sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "AAD Error Code {0}", aadError)); + sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "AAD Error Code AADSTS{0}", msalServiceException.ErrorCodes.FirstOrDefault())); } if (ex.InnerException != null) @@ -124,7 +123,7 @@ internal static string GetPiiScrubbedExceptionDetails(Exception ex) sb.AppendLine("=== End of inner exception stack trace ==="); } - sb.AppendLine("To see full exception details, enable Pii Logging. See https://aka.ms/msal-net-logging"); + sb.AppendLine("To see full exception details, enable PII Logging. See https://aka.ms/msal-net-logging"); if (ex.StackTrace != null) { diff --git a/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs b/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs index 28be1550fb..589fc61c79 100644 --- a/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs +++ b/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs @@ -69,7 +69,7 @@ public async Task WithCertificate_TestAsync(Cloud cloud, TargetFrameworks runOn, } [TestMethod] - //[DataRow(Cloud.Public, TargetFrameworks.NetFx | TargetFrameworks.NetCore)] + [DataRow(Cloud.Public, TargetFrameworks.NetFx | TargetFrameworks.NetCore)] //[DataRow(Cloud.Adfs, TargetFrameworks.NetFx)] [DataRow(Cloud.Arlington, TargetFrameworks.NetCore)] //[DataRow(Cloud.PPE)] - secret not setup @@ -306,7 +306,7 @@ private static IConfidentialClientApplication CreateApp(CredentialType credentia builder.WithCertificate(settings.GetCertificate()); break; case CredentialType.Secret: - builder.WithClientSecret(settings.GetSecret()); + builder.WithClientSecret("wfregrfd"); break; case CredentialType.ClientAssertion_Manual: From a223d6df9b5992f7a500188540406c152514b742 Mon Sep 17 00:00:00 2001 From: trwalke Date: Fri, 12 Jan 2024 02:26:18 -0800 Subject: [PATCH 4/8] revert --- .../HeadlessTests/ClientCredentialsTests.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs b/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs index 589fc61c79..28cb5b0b0a 100644 --- a/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs +++ b/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs @@ -57,9 +57,9 @@ public void TestInitialize() } [TestMethod] - [DataRow(Cloud.Public, TargetFrameworks.NetFx | TargetFrameworks.NetCore | TargetFrameworks.NetStandard )] + [DataRow(Cloud.Public, TargetFrameworks.NetFx | TargetFrameworks.NetCore | TargetFrameworks.NetStandard)] [DataRow(Cloud.Adfs, TargetFrameworks.NetCore)] - [DataRow(Cloud.PPE, TargetFrameworks.NetFx)] + [DataRow(Cloud.PPE, TargetFrameworks.NetFx)] [DataRow(Cloud.Public, TargetFrameworks.NetCore, true)] //[DataRow(Cloud.Arlington)] - cert not setup public async Task WithCertificate_TestAsync(Cloud cloud, TargetFrameworks runOn, bool useAppIdUri = false) @@ -69,7 +69,7 @@ public async Task WithCertificate_TestAsync(Cloud cloud, TargetFrameworks runOn, } [TestMethod] - [DataRow(Cloud.Public, TargetFrameworks.NetFx | TargetFrameworks.NetCore)] + //[DataRow(Cloud.Public, TargetFrameworks.NetFx | TargetFrameworks.NetCore)] //[DataRow(Cloud.Adfs, TargetFrameworks.NetFx)] [DataRow(Cloud.Arlington, TargetFrameworks.NetCore)] //[DataRow(Cloud.PPE)] - secret not setup @@ -140,7 +140,7 @@ public async Task WithClientClaims_SendX5C_OverrideClaims_TestAsync(Cloud cloud, } [TestMethod] - [DataRow(Cloud.Public, TargetFrameworks.NetCore)] + [DataRow(Cloud.Public, TargetFrameworks.NetCore)] public async Task WithOnBeforeTokenRequest_TestAsync(Cloud cloud, TargetFrameworks runOn) { IConfidentialAppSettings settings = ConfidentialAppSettings.GetSettings(cloud); @@ -153,7 +153,7 @@ public async Task WithOnBeforeTokenRequest_TestAsync(Cloud cloud, TargetFramewor .WithExperimentalFeatures(true) .WithTestLogging() .Build(); - + authResult = await confidentialApp .AcquireTokenForClient(settings.AppScopes) .OnBeforeTokenRequest((data) => @@ -176,7 +176,7 @@ public async Task WithOnBeforeTokenRequest_TestAsync(Cloud cloud, TargetFramewor .ExecuteAsync() .ConfigureAwait(false); - Assert.AreEqual(TokenSource.Cache, authResult.AuthenticationResultMetadata.TokenSource); + Assert.AreEqual(TokenSource.Cache, authResult.AuthenticationResultMetadata.TokenSource); } [TestMethod] @@ -306,7 +306,7 @@ private static IConfidentialClientApplication CreateApp(CredentialType credentia builder.WithCertificate(settings.GetCertificate()); break; case CredentialType.Secret: - builder.WithClientSecret("wfregrfd"); + builder.WithClientSecret(settings.GetSecret()); break; case CredentialType.ClientAssertion_Manual: @@ -418,8 +418,8 @@ private static string GetSignedClientAssertionUsingWilson( /// /// internal static string GetSignedClientAssertionManual( - string issuer, - string audience, + string issuer, + string audience, X509Certificate2 certificate) { const uint JwtToAadLifetimeInSeconds = 60 * 10; // Ten minutes From b951ad900433d10752ff566ca78c1c3314d0b9e1 Mon Sep 17 00:00:00 2001 From: trwalke Date: Fri, 12 Jan 2024 02:29:07 -0800 Subject: [PATCH 5/8] clean up --- .../HeadlessTests/ClientCredentialsTests.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs b/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs index 28cb5b0b0a..2fa34d1ba6 100644 --- a/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs +++ b/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs @@ -57,9 +57,9 @@ public void TestInitialize() } [TestMethod] - [DataRow(Cloud.Public, TargetFrameworks.NetFx | TargetFrameworks.NetCore | TargetFrameworks.NetStandard)] + [DataRow(Cloud.Public, TargetFrameworks.NetFx | TargetFrameworks.NetCore | TargetFrameworks.NetStandard )] [DataRow(Cloud.Adfs, TargetFrameworks.NetCore)] - [DataRow(Cloud.PPE, TargetFrameworks.NetFx)] + [DataRow(Cloud.PPE, TargetFrameworks.NetFx)] [DataRow(Cloud.Public, TargetFrameworks.NetCore, true)] //[DataRow(Cloud.Arlington)] - cert not setup public async Task WithCertificate_TestAsync(Cloud cloud, TargetFrameworks runOn, bool useAppIdUri = false) @@ -140,7 +140,7 @@ public async Task WithClientClaims_SendX5C_OverrideClaims_TestAsync(Cloud cloud, } [TestMethod] - [DataRow(Cloud.Public, TargetFrameworks.NetCore)] + [DataRow(Cloud.Public, TargetFrameworks.NetCore)] public async Task WithOnBeforeTokenRequest_TestAsync(Cloud cloud, TargetFrameworks runOn) { IConfidentialAppSettings settings = ConfidentialAppSettings.GetSettings(cloud); @@ -153,7 +153,7 @@ public async Task WithOnBeforeTokenRequest_TestAsync(Cloud cloud, TargetFramewor .WithExperimentalFeatures(true) .WithTestLogging() .Build(); - + authResult = await confidentialApp .AcquireTokenForClient(settings.AppScopes) .OnBeforeTokenRequest((data) => @@ -176,7 +176,7 @@ public async Task WithOnBeforeTokenRequest_TestAsync(Cloud cloud, TargetFramewor .ExecuteAsync() .ConfigureAwait(false); - Assert.AreEqual(TokenSource.Cache, authResult.AuthenticationResultMetadata.TokenSource); + Assert.AreEqual(TokenSource.Cache, authResult.AuthenticationResultMetadata.TokenSource); } [TestMethod] @@ -306,7 +306,7 @@ private static IConfidentialClientApplication CreateApp(CredentialType credentia builder.WithCertificate(settings.GetCertificate()); break; case CredentialType.Secret: - builder.WithClientSecret(settings.GetSecret()); + builder.WithClientSecret("wfregrfd"); break; case CredentialType.ClientAssertion_Manual: @@ -418,8 +418,8 @@ private static string GetSignedClientAssertionUsingWilson( /// /// internal static string GetSignedClientAssertionManual( - string issuer, - string audience, + string issuer, + string audience, X509Certificate2 certificate) { const uint JwtToAadLifetimeInSeconds = 60 * 10; // Ten minutes From 95fe68b9acbe942f1efad2eed44ffa731fdbb7b4 Mon Sep 17 00:00:00 2001 From: trwalke Date: Fri, 12 Jan 2024 02:34:00 -0800 Subject: [PATCH 6/8] clean up --- .../HeadlessTests/ClientCredentialsTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs b/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs index 2fa34d1ba6..28be1550fb 100644 --- a/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs +++ b/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/ClientCredentialsTests.cs @@ -306,7 +306,7 @@ private static IConfidentialClientApplication CreateApp(CredentialType credentia builder.WithCertificate(settings.GetCertificate()); break; case CredentialType.Secret: - builder.WithClientSecret("wfregrfd"); + builder.WithClientSecret(settings.GetSecret()); break; case CredentialType.ClientAssertion_Manual: From c50653ed47aa93398fc9d368be6255ae51a5b911 Mon Sep 17 00:00:00 2001 From: trwalke Date: Tue, 16 Jan 2024 11:01:53 -0800 Subject: [PATCH 7/8] Updating error code parsing --- .../Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs b/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs index e658183dc2..91ac752c24 100644 --- a/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs +++ b/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs @@ -113,7 +113,7 @@ internal static string GetPiiScrubbedExceptionDetails(Exception ex) { sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "HTTP StatusCode {0}", msalServiceException.StatusCode)); sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "CorrelationId {0}", msalServiceException.CorrelationId)); - sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "AAD Error Code AADSTS{0}", msalServiceException.ErrorCodes.FirstOrDefault())); + sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "AAD Error Code AADSTS{0}", string.Join(" ", msalServiceException.ErrorCodes))); } if (ex.InnerException != null) @@ -127,7 +127,7 @@ internal static string GetPiiScrubbedExceptionDetails(Exception ex) if (ex.StackTrace != null) { - sb.Append(Environment.NewLine + ex.StackTrace); + sb.AppendLine(ex.StackTrace); } } From 3d786cd9e15dafe27c649ff4a6b8863c1673ffa8 Mon Sep 17 00:00:00 2001 From: trwalke Date: Tue, 16 Jan 2024 19:55:43 -0800 Subject: [PATCH 8/8] Updating error codes --- .../Internal/Logger/LoggerHelper.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs b/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs index 91ac752c24..7601427a5d 100644 --- a/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs +++ b/src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs @@ -113,7 +113,10 @@ internal static string GetPiiScrubbedExceptionDetails(Exception ex) { sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "HTTP StatusCode {0}", msalServiceException.StatusCode)); sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "CorrelationId {0}", msalServiceException.CorrelationId)); - sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "AAD Error Code AADSTS{0}", string.Join(" ", msalServiceException.ErrorCodes))); + if (msalServiceException.ErrorCodes != null && msalServiceException.ErrorCodes.Count() > 0) + { + sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "Microsoft Entra ID Error Code AADSTS{0}", string.Join(" ", msalServiceException.ErrorCodes))); + } } if (ex.InnerException != null)