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

Google Drive OAuth without a browser #81

Open
psarossy opened this issue Mar 12, 2021 · 6 comments
Open

Google Drive OAuth without a browser #81

psarossy opened this issue Mar 12, 2021 · 6 comments
Labels
help wanted Extra attention is needed

Comments

@psarossy
Copy link

Describe the bug
Trying to set this up the first time on a headless server, and there are no instructions on how to authorize the app if there is no browser available to open.

To Reproduce
Steps to reproduce the behavior:

  1. follow the setup instructions
  2. Run the tool with --url on a drive link
  3. get stack trace as the authorization token is missing and it cannot open a browser

Expected behavior
Handle the exception and ask to copy paste the link, then copy back the authorization token.

Screenshots

Error initializing Google Drive, please check OpenDirectoryDownloader.GoogleDrive.json and/or remove the 'token.json' directory. See readme on Github for more help. ERROR: System.AggregateException: One or more errors occurred. (Failed to launch browser with "https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&response_type=code&client_id=[xxx].apps.googleusercontent.com&redirect_uri=http%3A%2F%2F127.0.0.1%3A42373%2Fauthorize%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.metadata.readonly" for authorization. See inner exception for details.)
 ---> System.NotSupportedException: Failed to launch browser with "https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&response_type=code&client_id=[xxx].apps.googleusercontent.com&redirect_uri=http%3A%2F%2F127.0.0.1%3A42373%2Fauthorize%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.metadata.readonly" for authorization. See inner exception for details.
 ---> System.ComponentModel.Win32Exception (2): No such file or directory
   at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start(String fileName, String arguments)
   at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.OpenBrowser(String url)
   at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.ReceiveCodeAsync(AuthorizationCodeRequestUrl url, CancellationToken taskCancellationToken)
   --- End of inner exception stack trace ---
   at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.ReceiveCodeAsync(AuthorizationCodeRequestUrl url, CancellationToken taskCancellationToken)
   at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.AuthorizeAsync(String userId, CancellationToken taskCancellationToken)
   at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(Initializer initializer, IEnumerable`1 scopes, String user, CancellationToken taskCancellationToken, IDataStore dataStore, ICodeReceiver codeReceiver)
   at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(ClientSecrets clientSecrets, IEnumerable`1 scopes, String user, CancellationToken taskCancellationToken, IDataStore dataStore, ICodeReceiver codeReceiver)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at OpenDirectoryDownloader.GoogleDrive.GoogleDriveIndexer..cctor()

Desktop (please complete the following information):

  • OS: Ubuntu
  • Version: 20.04
@Chaphasilor
Copy link
Contributor

As a workaround, you could try to use X11 so that the browser window is shown on your local machine :)

@KoalaBear84
Copy link
Owner

Hmm, the notification from GitHub was in the spam..

Well, what you can do it follow the steps on another computer, and copy the OpenDirectoryDownloader.GoogleDrive.json file to the server.

@psarossy
Copy link
Author

Yeah I had/have several ideas for workarounds, but mot applications that require this kind of auth tend to handle this gracefully in the cli. Usually present the URL to copy paste, then wait with a prompt for the token.

@KoalaBear84
Copy link
Owner

Currently there is no option like this, also not for regular desktop users.

Do you have an example of a console application with this technique for al Google services?

@psarossy
Copy link
Author

Don't have another app currently handy, but have used that workflow for sure before.

Basically instead of trying to open a browser, you can ask the user to copy paste the URL (exposed in the Exception) into a browser, and give a prompt to provide the challenge to be pasted back, then save it.

@KoalaBear84
Copy link
Owner

It looks like there is no way in the Google client to get this URL. We could indeed get it from the exception, which is not a good practice.

But if that would work, it want to redirect to an URL, and if you open the URL on another machine/IP, the localhost server will not be there and it fails.

Otherwise, if we could get some kind of token, I'm not sure if we can use that instead. I haven't found any solution with 30 minutes of Googling.

@KoalaBear84 KoalaBear84 added the help wanted Extra attention is needed label Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants