Skip to content

Commit

Permalink
Mark new API as experimental (#3405)
Browse files Browse the repository at this point in the history
* Mark new API as experimental

* Update src/client/Microsoft.Identity.Client/AppConfig/AbstractApplicationBuilder.cs

Co-authored-by: Peter M <34331512+pmaytak@users.noreply.github.com>

* Update tests/Microsoft.Identity.Test.Unit/PublicApiTests/LoggerTests.cs

Co-authored-by: Peter M <34331512+pmaytak@users.noreply.github.com>

Co-authored-by: SameerK-MSFT <83378772+SameerK-MSFT@users.noreply.github.com>
Co-authored-by: Peter M <34331512+pmaytak@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 20, 2022
1 parent 2d9afe4 commit 7916efc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Identity.Client.Http;
using Microsoft.Identity.Client.Instance;
using Microsoft.Identity.Client.Instance.Discovery;
using Microsoft.Identity.Client.Internal;
using Microsoft.Identity.Client.PlatformsCommon.Interfaces;
using Microsoft.Identity.Client.Utils;
using Microsoft.Identity.Json;
Expand Down Expand Up @@ -287,11 +288,14 @@ public T WithLogging(
/// You can set it to <c>true</c> for advanced debugging requiring PII
/// If both WithLogging apis are set, this one will override the other
/// </param>
/// <returns></returns>
/// <returns>The builder to chain the .With methods</returns>
/// <remarks>This is an experimental API. The method signature may change in the future without involving a major version upgrade.</remarks>
public T WithLogging(
IIdentityLogger identityLogger,
bool enablePiiLogging)
bool enablePiiLogging = false)
{
ValidateUseOfExperimentalFeature("IIdentityLogger");

Config.IdentityLogger = identityLogger;
Config.EnablePiiLogging = enablePiiLogging;
return (T)this;
Expand Down Expand Up @@ -540,7 +544,18 @@ internal ApplicationConfiguration BuildConfiguration()
return Config;
}

#region Authority
internal void ValidateUseOfExperimentalFeature([System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
{
if (!Config.ExperimentalFeaturesEnabled)
{
throw new MsalClientException(
MsalError.ExperimentalFeature,
MsalErrorMessage.ExperimentalFeature(memberName));
}
}


#region Authority
private void ResolveAuthority()
{
if (Config.Authority?.AuthorityInfo != null)
Expand Down
19 changes: 19 additions & 0 deletions tests/Microsoft.Identity.Test.Unit/PublicApiTests/LoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Identity.Client.Core;
using Microsoft.Identity.Client.Internal.Logger;
using Microsoft.Identity.Test.Common;
using Microsoft.Identity.Test.Common.Core.Helpers;
using Microsoft.Identity.Test.Common.Core.Mocks;
using Microsoft.IdentityModel.Abstractions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -219,6 +220,7 @@ public async Task IdentityLoggerOverridesLegacyLoggerTestAsync()
var app = ConfidentialClientApplicationBuilder
.Create(TestConstants.ClientId)
.WithClientSecret("secret")
.WithExperimentalFeatures()
.WithLogging(testLogger, false)
.WithLogging((level, message, containsPii) => { Assert.Fail("MSAL should not use the logging callback"); })
.WithHttpManager(httpManager)
Expand All @@ -236,5 +238,22 @@ public async Task IdentityLoggerOverridesLegacyLoggerTestAsync()
Assert.IsTrue(testLogger.StringBuilder.ToString().Contains("AcquireTokenByAuthorizationCode"));
}
}

[TestMethod]
public void IdentityLoggerExperimental()
{
using (var httpManager = new MockHttpManager())
{
TestIdentityLogger testLogger = new TestIdentityLogger();

var e = AssertException.Throws<MsalClientException>(() => ConfidentialClientApplicationBuilder
.Create(TestConstants.ClientId)
.WithClientSecret("secret")
.WithLogging(testLogger, false)
.Build());

Assert.AreEqual(MsalError.ExperimentalFeature, e.ErrorCode);
}
}
}
}

0 comments on commit 7916efc

Please sign in to comment.