WinForm with WebBrowser stops to catch callback

31 Views Asked by At

I developed a solution in .Net framework48. I have a Windows Form with an embedded webBrower. I am using it to authenticate users with an internal application, using WebBrowser_Navigated; I was ablet to catch the callback with the authorise code I need to get the toke. Everything was working weeks ago, but now the WindowsForm is no longer catching the callback. Nothing change in the code. One point to notice, if I change the properties ScriptErrorsSuppressed to false, I get an internet Redirection message. If I press yes, I get the call back with the code, but the code is unauthorised.

Here is the code I am using.

        public static void Authenticate()
        {
            using (var webBrowser = new WebBrowser())
            {
                webBrowser.Dock = DockStyle.Fill;
                webBrowser.ScriptErrorsSuppressed = false;
                var form = new Form
                {
                    Width = 600,
                    Height = 800,
                    StartPosition = FormStartPosition.CenterParent,
                    Controls = {webBrowser}
                };

                webBrowser.Navigated += WebBrowser_Navigated;
                webBrowser.Navigate(Manager.AuthoritySignUpSignIn, false);

                form.ShowDialog();
            }
        }


        private static void WebBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            if (e.Url.Authority != "jwt.ms") return;
            ((WebBrowser) sender).Parent.FindForm()?.Close();
            var query = e.Url.Query;
            _code = HttpUtility.ParseQueryString(query).Get("code");
            _authorisation = Task.Run(async () => await Manager.GetToken(_code)).Result;
        }

I can't use Microsoft.Web.WebView2 because won't work for the application I am building on. I tried to set ScriptErrorsSuppressed to false but this gave me back an unauthorised code to use.

0

There are 0 best solutions below