WebAuthenticationBroker.AuthenticateAsync freeze in UWP Xamarin

Mattia Vicari 16 Reputation points
2022-04-12T22:32:46.417+00:00

Hi all!
I am using the WebAuthenticationBroker.AuthenticateAsync to login to OneDrive using OAuth.
This has always worked well. In the last month, I see that the web broker "freezes" after the login completes (the popup window doesn't close).
My code is pretty simple:

WebAuthenticationResult Result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, authorizeUri, redirectUrl);

if (Result.ResponseStatus == WebAuthenticationStatus.Success)
{
   // Success!!
   // Get the code and go to the next step...
}

If I try to crash the AuthHost process, the window will close and I will be successful!! So, I think that I'm not going back for some reason...

Has anyone investigated this issue?

Thank you

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,316 questions
Universal Windows Platform (UWP)
Microsoft Authenticator
Microsoft Authenticator
A Microsoft app for iOS and Android devices that enables authentication with two-factor verification, phone sign-in, and code generation.
5,894 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,693 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,481 Reputation points
    2022-04-19T07:45:21.92+00:00

    Hi there,

    There are many reasons for UWP freezing, including code endless loops, asynchronous methods are not handled properly, program errors, etc. Most of them occur in asynchronous method processing and UI rendering.

    If your app first freezes, and then crashes after some time, then this could be because your tasks don't have correct exception handling. You might consider adding an UnobservedTaskException handler to your code to help you find this problem.

    TaskScheduler.UnobservedTaskException Event https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskscheduler.unobservedtaskexception?view=netframework-4.8

    I would also suggest you try to use the Visual Studio debugger to find out what the code is doing.

    ------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer–

    0 comments No comments