AcquireTokenInteractiveC
{
builder.WithAuthority(AuthorityHost.AbsoluteUri, tenantId);
}
- if (useEmbeddedWebView != null)
- {
- builder.WithUseEmbeddedWebView(useEmbeddedWebView.Value);
- }
- if (systemWebViewOptions != null)
+ if (browserOptions != null)
{
- builder.WithSystemWebViewOptions(systemWebViewOptions);
- }
- if (embeddedWebViewOptions != null)
- {
- builder.WithEmbeddedWebViewOptions(embeddedWebViewOptions);
+ if (browserOptions.UseEmbeddedWebView.HasValue)
+ {
+ builder.WithUseEmbeddedWebView(browserOptions.UseEmbeddedWebView.Value);
+ }
+ if (browserOptions.SystemBrowserOptions != null)
+ {
+ builder.WithSystemWebViewOptions(browserOptions.SystemBrowserOptions);
+ }
}
return await builder
.ExecuteAsync(async, cancellationToken)
diff --git a/sdk/identity/Azure.Identity/tests/CredentialTestBase.cs b/sdk/identity/Azure.Identity/tests/CredentialTestBase.cs
index c9c4077c5eb8e..b3250825a0ecd 100644
--- a/sdk/identity/Azure.Identity/tests/CredentialTestBase.cs
+++ b/sdk/identity/Azure.Identity/tests/CredentialTestBase.cs
@@ -448,7 +448,7 @@ public void TestSetup(TokenCredentialOptions options = null)
// Assert.AreEqual(tenantId, tId);
return publicResult;
};
- mockPublicMsalClient.InteractiveAuthFactory = (_, _, _, _, tenant, _, _) =>
+ mockPublicMsalClient.InteractiveAuthFactory = (_, _, _, _, tenant, _, _, _) =>
{
Assert.AreEqual(expectedTenantId, tenant, "TenantId passed to msal should match");
return result;
diff --git a/sdk/identity/Azure.Identity/tests/InteractiveBrowserCredentialTests.cs b/sdk/identity/Azure.Identity/tests/InteractiveBrowserCredentialTests.cs
index 4f4098c8112dd..9be5f2f6ad77a 100644
--- a/sdk/identity/Azure.Identity/tests/InteractiveBrowserCredentialTests.cs
+++ b/sdk/identity/Azure.Identity/tests/InteractiveBrowserCredentialTests.cs
@@ -9,6 +9,7 @@
using Azure.Core.TestFramework;
using Azure.Identity.Tests.Mock;
using Microsoft.Identity.Client;
+
using NUnit.Framework;
namespace Azure.Identity.Tests
@@ -186,7 +187,7 @@ public async Task LoginHint([Values(null, "fring@contoso.com")] string loginHint
{
var mockMsalClient = new MockMsalPublicClient
{
- InteractiveAuthFactory = (_, _, prompt, hintArg, _, _, _) =>
+ InteractiveAuthFactory = (_, _, prompt, hintArg, _, _, _, _) =>
{
Assert.AreEqual(loginHint == null ? Prompt.SelectAccount : Prompt.NoPrompt, prompt);
Assert.AreEqual(loginHint, hintArg);
@@ -305,5 +306,59 @@ public async Task InvokesBeforeBuildClientOnExtendedOptions()
Assert.True(beforeBuildClientInvoked);
}
+
+ [Test]
+ public async Task BrowserCustomizedOptionsHtmlMessage([Values(null, " Login Successfully.
")] string htmlMessageSuccess, [Values(null, " An error occured: {0}. Details {1}
")] string htmlMessageError)
+ {
+ var mockMsalClient = new MockMsalPublicClient
+ {
+ InteractiveAuthFactory = (_, _, _, _, _, _, browserOptions, _) =>
+ {
+ Assert.AreEqual(false, browserOptions.UseEmbeddedWebView);
+ Assert.AreEqual(htmlMessageSuccess, browserOptions.HtmlMessageSuccess);
+ Assert.AreEqual(htmlMessageError, browserOptions.HtmlMessageError);
+ return AuthenticationResultFactory.Create(Guid.NewGuid().ToString(), expiresOn: DateTimeOffset.UtcNow.AddMinutes(5));
+ }
+ };
+ var options = new InteractiveBrowserCredentialOptions()
+ {
+ BrowserCustomizedOptions = new BrowserCustomizationOptions()
+ {
+ UseEmbeddedWebView = false,
+ HtmlMessageSuccess = htmlMessageSuccess,
+ HtmlMessageError = htmlMessageError
+ }
+ };
+
+ var credential = InstrumentClient(new InteractiveBrowserCredential(default, "", options, default, mockMsalClient));
+
+ await credential.GetTokenAsync(new TokenRequestContext(MockScopes.Default));
+ }
+
+ [Test]
+ public async Task BrowserCustomizedUseEmbeddedWebView([Values(null, true, false)] bool useEmbeddedWebView, [Values(null, " An error occured: {0}. Details {1}
")] string htmlMessageError)
+ {
+ var mockMsalClient = new MockMsalPublicClient
+ {
+ InteractiveAuthFactory = (_, _, _, _, _, _, browserOptions, _) =>
+ {
+ Assert.AreEqual(useEmbeddedWebView, browserOptions.UseEmbeddedWebView);
+ Assert.AreEqual(htmlMessageError, browserOptions.HtmlMessageError);
+ return AuthenticationResultFactory.Create(Guid.NewGuid().ToString(), expiresOn: DateTimeOffset.UtcNow.AddMinutes(5));
+ }
+ };
+ var options = new InteractiveBrowserCredentialOptions()
+ {
+ BrowserCustomizedOptions = new BrowserCustomizationOptions()
+ {
+ UseEmbeddedWebView = useEmbeddedWebView,
+ HtmlMessageError = htmlMessageError
+ }
+ };
+
+ var credential = InstrumentClient(new InteractiveBrowserCredential(default, "", options, default, mockMsalClient));
+
+ await credential.GetTokenAsync(new TokenRequestContext(MockScopes.Default));
+ }
}
}
diff --git a/sdk/identity/Azure.Identity/tests/Mock/MockMsalPublicClient.cs b/sdk/identity/Azure.Identity/tests/Mock/MockMsalPublicClient.cs
index 20e83f421f2b8..a94a186706455 100644
--- a/sdk/identity/Azure.Identity/tests/Mock/MockMsalPublicClient.cs
+++ b/sdk/identity/Azure.Identity/tests/Mock/MockMsalPublicClient.cs
@@ -18,7 +18,7 @@ internal class MockMsalPublicClient : MsalPublicClient
public List Accounts { get; set; }
public Func AuthFactory { get; set; }
public Func UserPassAuthFactory { get; set; }
- public Func InteractiveAuthFactory { get; set; }
+ public Func InteractiveAuthFactory { get; set; }
public Func SilentAuthFactory { get; set; }
public Func ExtendedSilentAuthFactory { get; set; }
public Func DeviceCodeAuthFactory { get; set; }
@@ -30,7 +30,7 @@ public MockMsalPublicClient(AuthenticationResult result)
{
AuthFactory = (_, _) => result;
UserPassAuthFactory = (_, _) => result;
- InteractiveAuthFactory = (_, _, _, _, _, _, _) => result;
+ InteractiveAuthFactory = (_, _, _, _, _, _, _, _) => result;
SilentAuthFactory = (_, _) => result;
ExtendedSilentAuthFactory = (_, _, _, _, _, _) => result;
DeviceCodeAuthFactory = (_, _) => result;
@@ -72,9 +72,7 @@ protected override ValueTask AcquireTokenInteractiveCoreAs
string loginHint,
string tenantId,
bool enableCae,
- bool? useEmbeddedWebView,
- SystemWebViewOptions systemWebViewOptions,
- EmbeddedWebViewOptions embeddedWebViewOptions,
+ BrowserCustomizationOptions browserOptions,
bool async,
CancellationToken cancellationToken)
{
@@ -83,7 +81,7 @@ protected override ValueTask AcquireTokenInteractiveCoreAs
if (interactiveAuthFactory != null)
{
- return new ValueTask(interactiveAuthFactory(scopes, claims, prompt, loginHint, tenantId, async, cancellationToken));
+ return new ValueTask(interactiveAuthFactory(scopes, claims, prompt, loginHint, tenantId, async, browserOptions, cancellationToken));
}
if (authFactory != null)
{