0

I have a server and i want to provide users an option to upload files to Google Drive. I tried with using pydrive, my code is the following:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)

but when I send the OAuth link to other people they can't join because on their localhost:8080(the URI url) they have no local server. I am not 100% sure about this, but when they try to log in google says they can't reach localhost:8080, login works at the local server. I also tried with

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.CommandLineAuth()

Using this I couldn't even get it to work on the server even though I set up the credentials as "desktop application" on the google console. Error was:redirect_uri: urn:ietf:wg:oauth:2.0:oob when opening the OAuth link

Dioswison
  • 81
  • 9
  • 1
    Google removed [OAuth out-of-band (oob) flow](https://developers.googleblog.com/2022/02/making-oauth-flows-safer.html) You need to use localhost. – Linda Lawton - DaImTo Jul 22 '22 at 12:40
  • 1
    Welcome to stack please include an [example] and describe your issue. The code you have here is not enough to diagnose the issue. Why not follow the [standard samples](https://developers.google.com/drive/api/quickstart/python) – Linda Lawton - DaImTo Jul 22 '22 at 12:42
  • 1
    If the code is running on the server then you shouldn't be using an installed app. Unless the users are running a remote desktop and can agree to consent there. The browser window is going to open on the server. – Linda Lawton - DaImTo Jul 22 '22 at 12:55

1 Answers1

0

For future reference and visibility, I’m joining the information already provided by DaImTo in the comments and posting as an answer.

Given that the exception contains redirect_uri: urn:ietf:wg:oauth:2.0:oob, the library used for authentication must be using out-of-band flow.

However out-of-band flow of authentication was deprecated by Google on Feb 28, 2022. See this article for more information.

Additionally, if you are planning to run your code centralizing it on a Server, an “installed app” would not be recommended. See this page for more information about Using OAuth 2.0 for Installed Applications. Regardless, an OAuth scope consent must be provided within the app. If this script runs unattended on a server, it’ll require user interaction to accept/consent OAuth scopes for your application.

You may find quickstart samples provided by Google available in different programming languages on Drive API documentation. It is recommended to review those scripts for best practices of implementation and client library usage. You may find the Python Quickstart for Drive API here.

Although the root cause this time was identifiable given the characteristic Exception message provided, make sure to provide a minimal reproducible example when posting a question.

Gustavo
  • 639
  • 2
  • 4
  • I thought what i shared was a minimal reproducible example(with the same OAuth creds) what should i add to do it correctly? – Dioswison Jul 26 '22 at 13:37