public async Task NoBroker_WebUiOnly_Async() { // Arrange - common stuff using (MockHttpAndServiceBundle harness = CreateTestHarness()) { MockInstanceDiscovery(harness.HttpManager); ITokenCacheInternal cache = new TokenCache(harness.ServiceBundle, false); var requestParams = harness.CreateAuthenticationRequestParameters( TestConstants.AuthorityHomeTenant, TestConstants.s_scope, cache); var interactiveParameters = new AcquireTokenInteractiveParameters(); // Arrange - important for test requestParams.AppConfig.IsBrokerEnabled = false; var authCodeResult = new Tuple <AuthorizationResult, string>(new AuthorizationResult() { Code = "some_auth_code" }, "pkce_verifier"); _authCodeRequestComponentOverride.FetchAuthCodeAndPkceVerifierAsync(CancellationToken.None) .Returns(Task.FromResult(authCodeResult)); _authCodeExchangeComponentOverride.FetchTokensAsync(CancellationToken.None) .Returns(Task.FromResult(_msalTokenResponse)); InteractiveRequest interactiveRequest = new InteractiveRequest( requestParams, interactiveParameters, _authCodeRequestComponentOverride, _authCodeExchangeComponentOverride, _brokerExchangeComponentOverride); // Act AuthenticationResult result = await interactiveRequest.RunAsync().ConfigureAwait(false); // Assert - common stuff Assert.IsNotNull(result); Assert.AreEqual(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource); Assert.IsTrue(!string.IsNullOrEmpty(result.AccessToken)); Assert.AreEqual(1, cache.Accessor.GetAllAccessTokens().Count()); // Assert - orchestration #pragma warning disable VSTHRD101 // Avoid unsupported async delegates Received.InOrder(async() => { await _authCodeRequestComponentOverride .FetchAuthCodeAndPkceVerifierAsync(default)
private async Task <MsalTokenResponse> FetchTokensFromBrokerAsync(string brokerInstallUrl, CancellationToken cancellationToken) { IBroker broker = _serviceBundle.PlatformProxy.CreateBroker( _interactiveParameters.UiParent); ITokenRequestComponent brokerInteractiveRequest = _brokerInteractiveComponent ?? new BrokerInteractiveRequestComponent( _requestParams, _interactiveParameters, broker, brokerInstallUrl); return(await brokerInteractiveRequest.FetchTokensAsync(cancellationToken) .ConfigureAwait(false)); }