2

Use case: User uploads file from Angular application. The server gets it through the REST API and the backend uploads it to the users google drive.

I have an Angular Frontend and a flask REST API as the backend.

I need to create a custom auth flow for pydrive2. I cannot use gauth.LocalWebserverAuth() as that is suitable only on local machines.

I see this sample code at pydrive documentation for custom auth flow.

from pydrive2.auth import GoogleAuth

gauth = GoogleAuth()
auth_url = gauth.GetAuthUrl() # Create authentication url user needs to visit
code = AskUserToVisitLinkAndGiveCode(auth_url) # Your customized authentication flow
gauth.Auth(code) # Authorize and build service from the code

AskUserToVisitLinkAndGiveCode is the part that I am unable to understand. What should this function do? Should my backend redirect to the URI that I added as the redirect URI on google drive console? Or should I redirect the user to the auth_url link?

Another follow up question, but related to pydrive. How would I get the access_token and refresh_token in pydrive2 so that I can store them for this user in the database? I can see that I can save the credentials to a credentials.json file, and then open the file and then use it, but can I access them directly so that I can store them to the database without the need to write to the file?

shinz4u
  • 145
  • 1
  • 9

1 Answers1

0

It should be your own custom user input or anything that would let your users know and visit the link for the auth_url, grabs the code from there and capture the code to be passed into gauth.Auth(code)

Ritsard
  • 51
  • 1
  • 7