Esempio n. 1
0
        public async Task DefaultOsBrowserWebUi_CustomBrowser_Async()
        {
            bool customOpenBrowserCalled = false;
            var  options = new SystemWebViewOptions()
            {
                OpenBrowserAsync = (Uri u) =>
                {
                    customOpenBrowserCalled = true;
                    return(Task.FromResult(0));
                }
            };

            var webUI          = CreateTestWebUI(options);
            var requestContext = new RequestContext(TestCommon.CreateDefaultServiceBundle(), Guid.NewGuid());
            var responseUri    = new Uri(TestAuthorizationResponseUri);

            _tcpInterceptor.ListenToSingleRequestAndRespondAsync(
                TestPort,
                Arg.Any <Func <Uri, string> >(),
                CancellationToken.None)
            .Returns(Task.FromResult(responseUri));

            // Act
            AuthorizationResult authorizationResult = await webUI.AcquireAuthorizationAsync(
                new Uri(TestAuthorizationRequestUri),
                new Uri(TestRedirectUri),
                requestContext,
                CancellationToken.None).ConfigureAwait(false);

            // Assert that we didn't open the browser using platform proxy
            await _platformProxy.DidNotReceiveWithAnyArgs().StartDefaultOsBrowserAsync(default)
Esempio n. 2
0
        private async Task <AuthorizationResult> AcquireAuthCodeAsync(
            string redirectUri       = TestRedirectUri,
            string requestUri        = TestAuthorizationRequestUri,
            string responseUriString = TestAuthorizationResponseUri)
        {
            // Arrange
            var    requestContext = new RequestContext(TestCommon.CreateDefaultServiceBundle(), Guid.NewGuid());
            var    responseUri    = new Uri(responseUriString);
            IWebUI webUI          = new DefaultOsBrowserWebUi(_platformProxy, _logger, _tcpInterceptor);

            _tcpInterceptor.ListenToSingleRequestAndRespondAsync(
                TestPort,
                Arg.Any <Func <Uri, string> >(),
                CancellationToken.None)
            .Returns(Task.FromResult(responseUri));

            // Act
            AuthorizationResult authorizationResult = await webUI.AcquireAuthorizationAsync(
                new Uri(requestUri),
                new Uri(redirectUri),
                requestContext,
                CancellationToken.None).ConfigureAwait(false);

            // Assert that we opened the browser
            await _platformProxy.Received(1).StartDefaultOsBrowserAsync(requestUri)
            .ConfigureAwait(false);

            return(authorizationResult);
        }
        private async Task <Uri> InterceptAuthorizationUriAsync(
            Uri authorizationUri,
            Uri redirectUri,
            CancellationToken cancellationToken)
        {
            await _platformProxy.StartDefaultOsBrowserAsync(authorizationUri.ToString()).ConfigureAwait(false);

            return(await _tcpInterceptor.ListenToSingleRequestAndRespondAsync(
                       redirectUri.Port,
                       GetMessageToShowInBroswerAfterAuth,
                       cancellationToken)
                   .ConfigureAwait(false));
        }
Esempio n. 4
0
        private async Task <Uri> InterceptAuthorizationUriAsync(
            Uri authorizationUri,
            Uri redirectUri,
            CancellationToken cancellationToken)
        {
            Func <Uri, Task> defaultBrowserAction = (Uri u) => _platformProxy.StartDefaultOsBrowserAsync(u.AbsoluteUri);
            Func <Uri, Task> openBrowserAction    = _webViewOptions?.OpenBrowserAsync ?? defaultBrowserAction;

            await openBrowserAction(authorizationUri).ConfigureAwait(false);

            return(await _tcpInterceptor.ListenToSingleRequestAndRespondAsync(
                       redirectUri.Port,
                       GetResponseMessage,
                       cancellationToken)
                   .ConfigureAwait(false));
        }