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

Developer technologies .NET Xamarin
Developer technologies Universal Windows Platform (UWP)
Windows for business Windows Client for IT Pros User experience Other
Microsoft Security Microsoft Authenticator
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,916 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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.