question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GoogleWebAuthorizationBroker.AuthorizeAsync Hang when user closes browser

See original GitHub issue
What steps will reproduce the problem?
1. Use GoogleWebAuthorizationBroker.AuthorizeAsync to gain user credentials
2. User nether accepts nor rejects permission, but closes browser window/tab
3. Works on Calendar.VB.ConsoleApp, haven't tried others.

What is the expected output? What do you see instead?
An exception to be thrown which could be caught.
Program stays in loop w/o exit, even with await clause.

What version of the product are you using?
What is your operating system? Win7 and Win8
What is your IDE? VS2013
What is the .NET framework version? 4.0 and 4.5

Please provide any additional information below.
Others from SE with same issue:

http://stackoverflow.com/questions/24659654/google-drive-catch-events-during-aut
hentication
http://stackoverflow.com/questions/22995218/google-drive-oauth-connect-probem  
[Note, setting Await still wasn't able to wrap error]
http://stackoverflow.com/questions/23475498/oauth-lockup-google


Original issue reported on code.google.com by Michael....@gmail.com on 19 Nov 2014 at 2:43

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11

github_iconTop GitHub Comments

3reactions
jhavikas84commented, Feb 9, 2018

We can throw timeout exception using thread when the thread meets the timeout value, below is the code and it serves my purpose. Here i have set the timeout value to 2 mins (120,000 milliseconds).

using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(SystemDataUtils.ConvertToJson<GDriveConfiguration>()))) { UserCredential cred = null;

            var thread = new Thread(() =>
                                        cred = (GoogleWebAuthorizationBroker.AuthorizeAsync(
                                            GoogleClientSecrets.Load(stream).Secrets,
                                            Scopes,
                                            userName,
                                            CancellationToken.None,
                                            new FileDataStore(FileDataStore)).Result)
            )
            { IsBackground = false };

            thread.Start();
            if (!thread.Join(120000))
            {
                throw new Exception("Timeout exception..!!!");
            }
            else
            {
                return cred;
            }
        }
1reaction
chrisdunelmcommented, Mar 31, 2017

It is not possible, in general, to detect when the user has closed the browser window/tab. For example, if the user is already running their default browser, then GoogleWebAuthorizationBroker opens a new tab, this is not running in the process started in LocalServerCodeReceiver. That new process terminates immediately.

However, currently the CancellationToken passed to GoogleWebAuthorizationBroker.AuthorizeAsync is not honoured whilst waiting for the auth response. #968 filed to fix this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GoogleWebAuthorizationBroker.AuthorizeAsync() hangs if ...
It is not possible, in general, to detect when the user has closed the browser window/tab. For example, if the user is already...
Read more >
OAuth 2.0 | API Client Library for .NET
In this sample code a new UserCredential instance is created by calling the GoogleWebAuthorizationBroker.AuthorizeAsync method. This static ...
Read more >
Connecting to Google using OAuth2 and C# | Daimto
Using OAuth2 with an installed application C# .net core application how to configure File datastore to store your user credentials.
Read more >
OAuth 2.0 for Google Regular Accounts (installed ...
NET Core 2.0\C#\OAuthUniversalApp project on how to use OAuth to ... AuthorizeAsync call will open the browser window asking for // authorization.
Read more >
Class GoogleWebAuthorizationBroker
This class is only suitable for client-side use, as it starts a local browser that requires user interaction. Do not use this class...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found