nango icon indicating copy to clipboard operation
nango copied to clipboard

Google Drive and Google Sheet integration using single API endpoint

Open anuragphadke opened this issue 4 years ago • 5 comments

  • I am using existing GSheet API and want to increase the scope to Google Drive.
  • Added the GDrive scope
  • OAuth screen shows the correct new scopes

When I make the request (with appropriate headers): https:///proxy/google-drive/files?q=mimeType%3D%27application%2Fvnd.google-apps.spreadsheet%27&pizzly_pkey=<my_key>

{
    "error": {
        "type": "unknown_authentication",
        "message": "That authentication (auth_id) could not be found with the provided integration."
    }
}

Any idea if it is possible to use GDrive and GSheets API using the same OAuth token?

anuragphadke avatar Apr 13 '21 04:04 anuragphadke

Since Google is using differing subdomains for each of their APIs, the integrations have been set up for ease of use rather than flexibility. That makes your use case a bit harder, as the proxy is hard-coded for whichever URL an integration is configured with.

One approach you could try is creating a custom Google integration that makes the subdomain configurable by the user (somewhat like the basecamp integration uses a header to configure the URL).

markmichon avatar Apr 13 '21 17:04 markmichon

@markmichon : good suggestion. I was planning to add an advanced integration where user can come in and add a JSON in the scopes section. The JSON will look something like this:

{
	"request": [{
			"baseURL": "https://www.googleapis.com/analytics/v3/",
			"headers": {
				"Accept": "application/json",
				"Authorization": "Bearer ${auth.accessToken}",
				"User-Agent": "Pizzly"
			},
			"scopes": [
				"https://www.googleapis.com/auth/analytics",
				"https://www.googleapis.com/auth/analytics.readonly"
			]
		},
		{
			"baseURL": "https://www.googleapis.com/drive/v1/",
			"headers": {
				"Accept": "application/json",
				"Authorization": "Bearer ${auth.accessToken}",
				"User-Agent": "Pizzly"
			},
			"scopes": [
				"https://www.googleapis.com/auth/drive",
				"https://www.googleapis.com/auth/drive.file"
			]
		}
	]
}

Does this make sense? Happy to open a PR if the above is in-line with what you are thinking..

anuragphadke avatar Apr 14 '21 01:04 anuragphadke

I worry it's an overly complex solution. I was thinking more like having a unified google integration that reduces the path:


{
  "name": "Google",
  "auth": {
    "authorizationURL": "https://accounts.google.com/o/oauth2/v2/auth",
    "tokenURL": "https://www.googleapis.com/oauth2/v4/token",
    "authType": "OAUTH2",
    "tokenParams": { "grant_type": "authorization_code" },
    "authorizationParams": { "prompt": "consent", "access_type": "offline" },
    "auth": {
      "response_type": "code"
    }
  },
  "request": {
    "baseURL": "https://www.googleapis.com/",
    "headers": {
      "Accept": "application/json",
      "Authorization": "Bearer ${auth.accessToken}",
      "User-Agent": "Pizzly"
    }
  }
}

Then it would require any proxy users to do the full path on top of that, so ... drive/v3/etc/etc/etc. Might be worth trying something like that locally to see if it solves your use case before embarking on any major rewrites.

markmichon avatar Apr 15 '21 17:04 markmichon

@markmichon : fair suggestion, one question: where will the scopes and endpoints reside? for eg: analytics => scopes:

				"https://www.googleapis.com/auth/analytics",
				"https://www.googleapis.com/auth/analytics.readonly"

endpoint:

"analytics/v3/"

drive => scopes:

				"https://www.googleapis.com/auth/drive",
				"https://www.googleapis.com/auth/drive.file"

endpoint:

"drive/v1/"

trying to figure out the best way for user to add scopes/endpoints

anuragphadke avatar Apr 16 '21 15:04 anuragphadke

@markmichon : just created a PR at https://github.com/Bearer/Pizzly/pull/223 that I think can benefit everyone.

anuragphadke avatar Apr 21 '21 03:04 anuragphadke