iterative / PyDrive2

Google Drive API Python wrapper library. Maintained fork of PyDrive.
https://docs.iterative.ai/PyDrive2
Other
565 stars 70 forks source link

Create Succesfull Authentication using Google OAuth client ID for a remote server accessible via SSH in a local machine #327

Closed mrgransky closed 8 months ago

mrgransky commented 8 months ago

Assumption:

google_api_oauth

Given quickstart.py:

from pydrive2.auth import GoogleAuth

gauth = GoogleAuth()
gauth.LocalWebserverAuth()

Authentication using my google account works fine in my local laptop with the text: The authentication flow has completed. on web browser and Authentication successful. in terminal.

Problem:

I would like to run this authentication in a remote server (SLURM super computer) without a graphical environment, which I access it via SSH command as $ ssh alijanif@puhti.csc.fi in my local laptop.

So I do the following, in working directory (containing client_secrets.json file) of my remote server after successful SSH login:

$ python quickstart.py 
Your browser has been opened to visit:

    https://accounts.google.com/o/oauth2/auth?client_id=<my client id>&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&access_type=online&response_type=code

Clicking on the provided link, fails to authenticate me using my google account, The connection failed on web browser!

in a web browser, I get the following link using that http://localhost:8080/ I provided in Authorised redirect URIs:

http://localhost:8080/?code=4%2F0AfJohXnpLFPEPEBOaYJNRUBB4eOMgtRGuWmLzN39mzH0XjcW8lno52y3PGhYZzbjorfqlA&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive

What is the easiest workaround to fix this issue for remote servers?

shcheklein commented 8 months ago

@mrgransky you have two options.