diff --git a/src/client/Microsoft.Identity.Client/Internal/Requests/Silent/SilentRequest.cs b/src/client/Microsoft.Identity.Client/Internal/Requests/Silent/SilentRequest.cs index 6b945ee51a..ed4ab7eddf 100644 --- a/src/client/Microsoft.Identity.Client/Internal/Requests/Silent/SilentRequest.cs +++ b/src/client/Microsoft.Identity.Client/Internal/Requests/Silent/SilentRequest.cs @@ -66,20 +66,12 @@ protected override async Task ExecuteAsync(CancellationTok _logger.Info("Broker is configured and enabled, attempting to use broker instead."); var brokerResult = await _brokerStrategyLazy.Value.ExecuteAsync(cancellationToken).ConfigureAwait(false); + // fallback to local cache if broker fails if (brokerResult != null) { _logger.Verbose(() => "Broker responded to silent request."); return brokerResult; } - else - { - _logger.Verbose(() => "Broker could not satisfy the silent request."); - throw new MsalUiRequiredException( - MsalError.FailedToAcquireTokenSilentlyFromBroker, - "Broker could not satisfy the silent request.", - null, - UiRequiredExceptionClassification.AcquireTokenSilentFailed); - } } _logger.Verbose(() => "Attempting to acquire token using local cache."); diff --git a/tests/Microsoft.Identity.Test.Unit/BrokerTests/BrokerRequestTests.cs b/tests/Microsoft.Identity.Test.Unit/BrokerTests/BrokerRequestTests.cs index f0d9ac295b..5a753c45a5 100644 --- a/tests/Microsoft.Identity.Test.Unit/BrokerTests/BrokerRequestTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/BrokerTests/BrokerRequestTests.cs @@ -526,7 +526,7 @@ public async Task NullBroker_AcquireSilentInteractive_Async() } catch (MsalUiRequiredException e) { - Assert.AreEqual("failed_to_acquire_token_silently_from_broker", e.ErrorCode); + Assert.AreEqual("no_tokens_found", e.ErrorCode); harness.HttpManager.AddInstanceDiscoveryMockHandler(); harness.HttpManager.AddSuccessTokenResponseMockHandlerForPost(); diff --git a/tests/Microsoft.Identity.Test.Unit/RequestsTests/SilentRequestTests.cs b/tests/Microsoft.Identity.Test.Unit/RequestsTests/SilentRequestTests.cs index 5bfb165b9e..1de35d0ee9 100644 --- a/tests/Microsoft.Identity.Test.Unit/RequestsTests/SilentRequestTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/RequestsTests/SilentRequestTests.cs @@ -130,25 +130,15 @@ public async Task BrokerSilentRequestLocalCacheTestAsync(bool brokerConfiguredBy var request = new SilentRequest(harness.ServiceBundle, parameters, silentParameters); - if (brokerConfiguredByUser) //When broker is enabled, local cache should not be used - { - var exception = await AssertException.TaskThrowsAsync(() => - request.RunAsync(default) - ,false - ).ConfigureAwait(false); - - Assert.IsNotNull(exception); - Assert.AreEqual(MsalError.FailedToAcquireTokenSilentlyFromBroker, exception.ErrorCode); - Assert.AreEqual("Broker could not satisfy the silent request.", exception.Message); - } - else - { - var result = await request.RunAsync(default).ConfigureAwait(false); + var result = await request.RunAsync(default).ConfigureAwait(false); - Assert.IsNotNull(result); - Assert.IsNotNull(result.AccessToken); - Assert.AreEqual(TestConstants.s_scope.AsSingleString(), result.Scopes.AsSingleString()); - Assert.AreEqual(brokerID, result.Account.Username); + // even if broker is configured by user but not installed, the result will be from the local cache + Assert.IsNotNull(result); + Assert.IsNotNull(result.AccessToken); + Assert.AreEqual(TestConstants.s_scope.AsSingleString(), result.Scopes.AsSingleString()); + Assert.AreEqual(brokerID, result.Account.Username); + if (!brokerConfiguredByUser) + { await mockBroker.DidNotReceiveWithAnyArgs().AcquireTokenSilentAsync(null, null).ConfigureAwait(false); } }