Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem authenticating to Blogger using Oauth2 and GoogleWebAuthorizationBroker.AuthorizeAsync #907

Closed
pixel3cs opened this issue Jan 24, 2017 · 9 comments
Assignees

Comments

@pixel3cs
Copy link

pixel3cs commented Jan 24, 2017

I've tried many things, tried to authenticate to Blogger using many samples from the web, tried with SharpDevelop, tried with Visual Studio 2015, tried with .NET 3.5, tried with .NET 4.5.2 and I get the same error every time coming from mscorlib "The directory name is invalid".

the_directory_name_is_invalid

It looks like something from Google API, class "LocalServerCodeReceiver.cs:line line 86" is not going well. There is a Process start at the line which fails !!!! Why ????? I have the latest nuggets for Google.Apis (Google.Apis v1.20.0, Google.Apis.Auth v1.20.0, Google.Apis.Blogger.v3 1.20.0.111, Google.Apis.Core v1.20.0, Google.Apis.Oauth2.v2 v1.20.0.672)

Please help me, I can provide more info if needed, even the solution and everything that will help me to use Google Api to insert and update Blogger posts from .NET.

The stacktrace is:

at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.d__6.MoveNext() in C:\Apiary\v1.20\google-api-dotnet-client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\LocalServerCodeReceiver.cs:line 86
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__8.MoveNext() in C:\Apiary\v1.20\google-api-dotnet-client\Src\Support\GoogleApis.Auth\OAuth2\AuthorizationCodeInstalledApp.cs:line 77
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__4.MoveNext() in C:\Apiary\v1.20\google-api-dotnet-client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line 134
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext() in C:\Apiary\v1.20\google-api-dotnet-client\Src\Support\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line 60

@jskeet
Copy link
Collaborator

jskeet commented Jan 24, 2017

I suspect the exception details would be useful here - you've shown us the stack trace, but not the exception, unless that's what you mean by "the directory name is invalid". (What's the exception type? Any more detail about which directory it's looking at?)

@LindaLawton
Copy link
Collaborator

@pixel3cs
Copy link
Author

jskeet, the exception message is in the attached picture. It's "The directory name is invalid". I don't know more about the invalid Directory because it's a Google API internal exception. I hope someone to understand by looking in LocalServerCodeReceiver.cs:line line 86, where a Process.Start is called and fails !!!

LindaLawton, :( I get the same error, see the pic. I did nothing at Oauth2Authentication.cs class, just calling the method with my parameters.
dir_name_not_valid

@LindaLawton
Copy link
Collaborator

Ok i will check it in the morning.

@pixel3cs
Copy link
Author

While digging a little I think I found the problem, but the fix will require a new release of Google API DLLs.

My error is thrown in Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.cs line 82 when a Process.Start() is called and a "The directory name is invalid" error is generated. While looking at the LocalServerCodeReceiver.cs code, line 82 (https://github.com/google/google-api-dotnet-client/blob/master/Src/Support/GoogleApis.Auth.DotNet4/OAuth2/LocalServerCodeReceiver.cs), I found the method ReceiveCodeAsync() and the Process.Start(authorizationUrl); at line 86 which I think is generating the problem.

I'm wondering why the Google API tries to "Open a browser with authorizationUrl URL" at that line of code ? I don't know, but... opening a browser URL with Process.Start() could generate problems on some machines, as I found here: http://stackoverflow.com/questions/7693429/process-start-to-open-an-url-getting-an-exception

There are few options to fix this:
1 - make sure the authorizationUrl is well formatted and the Process.Start(URL) treats all machine-specific behaviours (make sure to catch Win32Exception and start the process using Process.Start("IExplore.exe", "http://myurl");).

2 - If the scope will let you, use a WebClient or another class to make a web request to that URL

Please let me know when a new release is available for Google.Apis.Auth.OAuth2 nuget

@LindaLawton
Copy link
Collaborator

LindaLawton commented Jan 25, 2017

I cant recreate this. I created two separate console applications .net 4.6.1 and .net 4.0 both work fine i am not seeing your problem. Note: We don't support .net 3.5 so its not going to work and we don't completely support .net 4.0 any more either. so make sure you are using at least .net 4.5

We need to prompt the user for authenticating using the auth uri. Personally i think start process

Process.Start("IExplore.exe", "http://myurl");).

Is IMO a bad idea considering that Mircorsoft is moving away from IE to edge and I for one would rather spawn the users default browser then force them to use a browser they don't prefer.

Can i get some information on your system and what user you are currently running as it almost sounds like you cant access System.Environment.SpecialFolder.Personal.

@pixel3cs
Copy link
Author

I'm using Windows 10 and .NET 4.5.
I was able to fix the problem and also reproduce the issue.

My problem was that my system wouldn't start the Default Browser when Process.Start("URL") is called because somehow Edge was deactivated. When I tried to manually set the default browser from Edge to Chrome in the Default Apps interface it didn't worked. I found a way to reinstall Edge and now the Google API DLL is working, Edge was showing and I was able to allow access to Blogger for my app.

I still think the Process.Start(URL) from LocalServerCodeReceiver should take into consideration if no (default) browser is present in the system and throw the appropiate exception.

A "try { Process.Start(URL); } catch { throw new Exception("Default browser could not be found" }" should do it.

@LindaLawton
Copy link
Collaborator

I think the instance of a user not having a default browser selected is pretty low. That being said I am all for notifying users of potential issues with nice messages.

You are welcome to submit a pull request if you want to fix it since your the one who found it :)

chrisdunelm added a commit to chrisdunelm/google-api-dotnet-client that referenced this issue Mar 28, 2017
Log error, and provide a moer helpful exception message

Updates googleapis#907
chrisdunelm added a commit that referenced this issue Mar 28, 2017
Log error, and provide a moer helpful exception message

Updates #907
@chrisdunelm
Copy link
Contributor

We definitely want to maintain the current behaviour of using the default browser.
As suggested, #957 throws a more helpful exception which should make problem-solving simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants